Skip to content

Commit

Permalink
fix hello_world example
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraef committed Dec 3, 2024
1 parent cbbf05a commit 40e0d91
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ async fn main() -> Result<(), Error> {

let (mut tx, mut rx) = websocket.split();

tokio::task::spawn_local(async move {
for i in 1..11 {
tx.send(Message::Text(format!("Hello, World! #{i}")))
.await
.unwrap();
}
});

while let Some(message) = rx.try_next().await? {
if let Message::Text(text) = message {
println!("received: {text}");
}
}
futures_util::future::join(
async move {
for i in 1..11 {
tx.send(Message::Text(format!("Hello, World! #{i}")))
.await
.unwrap();
}
},
async move {
while let Some(message) = rx.try_next().await.unwrap() {
if let Message::Text(text) = message {
println!("received: {text}");
}
}
},
)
.await;

Ok(())
}

0 comments on commit 40e0d91

Please sign in to comment.