Skip to content

Commit 40e0d91

Browse files
committed
fix hello_world example
1 parent cbbf05a commit 40e0d91

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

examples/hello_world.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ async fn main() -> Result<(), Error> {
1414

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

17-
tokio::task::spawn_local(async move {
18-
for i in 1..11 {
19-
tx.send(Message::Text(format!("Hello, World! #{i}")))
20-
.await
21-
.unwrap();
22-
}
23-
});
24-
25-
while let Some(message) = rx.try_next().await? {
26-
if let Message::Text(text) = message {
27-
println!("received: {text}");
28-
}
29-
}
17+
futures_util::future::join(
18+
async move {
19+
for i in 1..11 {
20+
tx.send(Message::Text(format!("Hello, World! #{i}")))
21+
.await
22+
.unwrap();
23+
}
24+
},
25+
async move {
26+
while let Some(message) = rx.try_next().await.unwrap() {
27+
if let Message::Text(text) = message {
28+
println!("received: {text}");
29+
}
30+
}
31+
},
32+
)
33+
.await;
3034

3135
Ok(())
3236
}

0 commit comments

Comments
 (0)