aboutsummaryrefslogtreecommitdiff
path: root/examples/basalt.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2021-10-13 17:30:41 +0200
committerAlex Auvolat <alex@adnab.me>2021-10-13 17:30:41 +0200
commit7eea46dcf3f93377163a51288a1e9a807584256c (patch)
tree8b462c6d6c8f8d6af90cebc49eed11cfbfa165e9 /examples/basalt.rs
parentbc86bd3986429c4dac00a2cdb5cf8e30a092b6f5 (diff)
downloadnetapp-7eea46dcf3f93377163a51288a1e9a807584256c.tar.gz
netapp-7eea46dcf3f93377163a51288a1e9a807584256c.zip
Properly implement watches for Basalt
Diffstat (limited to 'examples/basalt.rs')
-rw-r--r--examples/basalt.rs12
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);