aboutsummaryrefslogtreecommitdiff
path: root/p2p/examples
diff options
context:
space:
mode:
authorhozan23 <hozan23@karyontech.net>2024-05-22 18:02:51 +0200
committerhozan23 <hozan23@karyontech.net>2024-05-22 18:02:51 +0200
commit5df6812dd2254b871eb773dc626b89646ca87495 (patch)
tree18828be9c86aba205d30086f705f2c6e2aeee975 /p2p/examples
parentc2860d3266aa1233787400b163d527fdc7dafe61 (diff)
p2p: monitor system use core::EventSys instead of pubsub pattern
Diffstat (limited to 'p2p/examples')
-rw-r--r--p2p/examples/monitor.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/p2p/examples/monitor.rs b/p2p/examples/monitor.rs
index 5da55aa..7b9e5d2 100644
--- a/p2p/examples/monitor.rs
+++ b/p2p/examples/monitor.rs
@@ -61,12 +61,29 @@ fn main() {
let exc = ex.clone();
run_executor(
async {
- let monitor = backend.monitor().await;
+ let monitor = backend.monitor();
+ let conn_listener = monitor.conn_events().await;
+ let peerpool_listener = monitor.peer_pool_events().await;
+ let discovery_listener = monitor.discovery_events().await;
let monitor_task = exc.spawn(async move {
loop {
- let event = monitor.recv().await.unwrap();
- println!("{}", event);
+ let event = conn_listener.recv().await.unwrap();
+ println!("New connection event: {}", event);
+ }
+ });
+
+ let monitor_task2 = exc.spawn(async move {
+ loop {
+ let event = peerpool_listener.recv().await.unwrap();
+ println!("New peer pool event: {}", event);
+ }
+ });
+
+ let monitor_task3 = exc.spawn(async move {
+ loop {
+ let event = discovery_listener.recv().await.unwrap();
+ println!("New discovery event: {}", event);
}
});
@@ -80,6 +97,8 @@ fn main() {
backend.shutdown().await;
monitor_task.cancel().await;
+ monitor_task2.cancel().await;
+ monitor_task3.cancel().await;
},
ex,
);