From 5df6812dd2254b871eb773dc626b89646ca87495 Mon Sep 17 00:00:00 2001 From: hozan23 Date: Wed, 22 May 2024 18:02:51 +0200 Subject: p2p: monitor system use core::EventSys instead of pubsub pattern --- p2p/examples/monitor.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'p2p/examples') 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, ); -- cgit v1.2.3