diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/basalt.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/examples/basalt.rs b/examples/basalt.rs index 63b4b4c..85fbb58 100644 --- a/examples/basalt.rs +++ b/examples/basalt.rs @@ -12,6 +12,8 @@ use structopt::StructOpt; use sodiumoxide::crypto::auth; use sodiumoxide::crypto::sign::ed25519; +use tokio::sync::watch; + use netapp::endpoint::*; use netapp::peering::basalt::*; use netapp::proto::*; @@ -126,18 +128,18 @@ async fn main() { let watch_cancel = netapp::util::watch_ctrl_c(); tokio::join!( - example.clone().sampling_loop(), + example.clone().sampling_loop(watch_cancel.clone()), example .netapp .clone() - .listen(listen_addr, public_addr, watch_cancel), - example.basalt.clone().run(), + .listen(listen_addr, public_addr, watch_cancel.clone()), + example.basalt.clone().run(watch_cancel.clone()), ); } impl Example { - async fn sampling_loop(self: Arc<Self>) { - loop { + async fn sampling_loop(self: Arc<Self>, must_exit: watch::Receiver<bool>) { + while !*must_exit.borrow() { tokio::time::sleep(Duration::from_secs(10)).await; let peers = self.basalt.sample(10); |