aboutsummaryrefslogtreecommitdiff
path: root/p2p/examples
diff options
context:
space:
mode:
Diffstat (limited to 'p2p/examples')
-rw-r--r--p2p/examples/chat.rs6
1 files changed, 1 insertions, 5 deletions
diff --git a/p2p/examples/chat.rs b/p2p/examples/chat.rs
index 5867c8b..2ea6b2c 100644
--- a/p2p/examples/chat.rs
+++ b/p2p/examples/chat.rs
@@ -69,11 +69,8 @@ impl Protocol for ChatProtocol {
}
});
- let listener = self.peer.register_listener::<Self>().await;
loop {
- let event = listener.recv().await.expect("Receive new protocol event");
-
- match event {
+ match self.peer.recv::<Self>().await? {
ProtocolEvent::Message(msg) => {
let msg = String::from_utf8(msg).expect("Convert received bytes to string");
println!("{msg}");
@@ -85,7 +82,6 @@ impl Protocol for ChatProtocol {
}
task.cancel().await;
- listener.cancel().await;
Ok(())
}