diff --git a/Cargo.lock b/Cargo.lock index 9951cb54..54ead485 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -93,7 +93,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bromine" -version = "0.17.1" +version = "0.18.0" dependencies = [ "async-trait", "bincode", diff --git a/Cargo.toml b/Cargo.toml index 68dcbaa9..fb6e652e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bromine" -version = "0.17.1" +version = "0.18.0" authors = ["trivernis "] edition = "2018" readme = "README.md" diff --git a/README.md b/README.md index 6a4c26ad..2f36a63a 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ use tokio::net::TcpListener; async fn handle_ping(ctx: &Context, event: Event) -> Result<()> { println!("Received ping event."); ctx.emit("pong", ()).await?; - Ok(()) + Ok(Response::empty()) } #[tokio::main] @@ -31,8 +31,15 @@ async fn main() { .on("ping", callback!(handle_ping)) .build_client().await.unwrap(); -// emit an initial event - let response = ctx.emit("ping", ()).await_response().await?; + // emit an event and wait for responses + let response = ctx.emit("ping", ()).await_reply().await?; + + // emit an event and get all responses as stream + let stream = ctx.emit("ping", ()).stream_replies().await?; + + while let Some(Ok(event)) = stream.next().await { + println!("{}", event.name()); + } } ``` @@ -50,7 +57,10 @@ async fn main() { // register callback .on("ping", callback!(ctx, event, async move { println!("Received ping event."); - Ok(()) + for _ in 0..10 { + ctx.emit("pong", ()).await?; + } + Ok(Response::empty()) })) .build_server().await.unwrap(); }