Expand description
This is a crate for broadcasting events to multiple clients and waiting for each client to receive it before sending another event to that client. If an event was failed to send, or if the number of events in the queue exceeds the limit, then the client is removed from the event queue.
§Example
#[derive(Clone)]
struct FooEvent {
state: String,
progress: u8,
}
impl Event for FooEvent {
fn can_merge(&self, other: &FooEvent) -> bool {
self.state == other.state
}
}
struct FooNotifier {
proxy: FooProxy,
}
impl Notify for FooNotifier {
type Event = FooEvent;
type NotifyFuture = BoxFuture<'static, Result<(), ClosedClient>>;
fn notify(&self, event: FooEvent) -> Self::NotifyFuture {
self.proxy.on_event(&event).map(|result| result.map_err(|_| ClosedClient)).boxed()
}
}
async fn foo(proxy: FooProxy) {
let (event_queue, mut handle) = EventQueue::<FooNotifier>::new();
let fut = async move {
handle.add_client(FooNotifier { proxy }).await.unwrap();
handle.queue_event(FooEvent { state: "new state".to_string(), progress: 0 }).await.unwrap();
};
future::join(fut, event_queue).await;
}
Structs§
- Closed
Client - The client is closed and should be removed from the event queue.
- Control
Handle - A control handle that can control the event queue.
- Event
Queue - An event queue for broadcasting events to multiple clients. Clients that failed to receive events or do not receive events fast enough will be dropped.
- Event
Queue Dropped - The event queue future was dropped before calling control handle functions.
- Timed
Out - The flush operation timed out.