Async Message Bus for Rust
Inspired by Actix
// Handler is Sync and we can spawn many of concurrent tasks
pub trait Handler
pub trait AsyncHandler
// Handler is not Sync and we cannot spawn many of concurrent tasks same time (uses synchronization primitives such as Mutex or RwLock)
pub trait SynchronizedHandler
pub trait AsyncSynchronizedHandler
// Handler is not Sync and handler will process items in batched mode
pub trait BatchSynchronizedHandler
pub trait AsyncBatchSynchronizedHandler
``
4. Handler Kinds:
1. No Synchronization needed (Handler is
Send+
Sync)
* Not batched operations **(implemented)**
- sync (spawn_blocking)
- async (spawn)
* Batched
- sync (spawn_blocking)
- async (spawn)
2. Synchronization needed (Handler is
Sync+
!Send)
* Not batched operations **(implemented)**
- sync (spawn_blocking)
- async (spawn)
* Batched **(implemented)**
- sync (spawn_blocking)
- async (spawn)
3. Synchronization needed and thread dedicated (Handler is
!Sync+
!Send`)
* Not batched operations
- sync (spawnblocking)
- async (spawn)
* Batched
- sync (spawnblocking)
- async (spawn)
struct TmpReceiver;
impl AsyncHandler
bus.send(2i64).await?;
Ok(())
}
}
impl AsyncHandler
Ok(())
}
}
async fn main() {
let (b, poller) = Bus::build()
.register(TmpReceiver)
.subscribe::
b.send(1i32).await.unwrap();
poller.await
} ```