From 70839d70d86354232f168e63ce4062219acb85c7 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 13 Oct 2021 17:12:13 +0200 Subject: Try to handle termination and closing of stuff properly --- examples/basalt.rs | 13 ++++++++++--- examples/fullmesh.rs | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'examples') diff --git a/examples/basalt.rs b/examples/basalt.rs index 7093e05..63b4b4c 100644 --- a/examples/basalt.rs +++ b/examples/basalt.rs @@ -5,9 +5,9 @@ use std::time::Duration; use log::{debug, info, warn}; +use async_trait::async_trait; use serde::{Deserialize, Serialize}; use structopt::StructOpt; -use async_trait::async_trait; use sodiumoxide::crypto::auth; use sodiumoxide::crypto::sign::ed25519; @@ -122,9 +122,15 @@ async fn main() { let listen_addr = opt.listen_addr.parse().unwrap(); let public_addr = opt.public_addr.map(|x| x.parse().unwrap()); + + let watch_cancel = netapp::util::watch_ctrl_c(); + tokio::join!( example.clone().sampling_loop(), - example.netapp.clone().listen(listen_addr, public_addr), + example + .netapp + .clone() + .listen(listen_addr, public_addr, watch_cancel), example.basalt.clone().run(), ); } @@ -141,7 +147,8 @@ impl Example { let self2 = self.clone(); tokio::spawn(async move { match self2 - .example_endpoint.call(&p, ExampleMessage { example_field: 42 }, PRIO_NORMAL) + .example_endpoint + .call(&p, ExampleMessage { example_field: 42 }, PRIO_NORMAL) .await { Ok(resp) => debug!("Got example response: {:?}", resp), diff --git a/examples/fullmesh.rs b/examples/fullmesh.rs index f40591a..67861a7 100644 --- a/examples/fullmesh.rs +++ b/examples/fullmesh.rs @@ -87,6 +87,11 @@ async fn main() { hex::encode(&privkey.public_key()), listen_addr); + let watch_cancel = netapp::util::watch_ctrl_c(); + let public_addr = opt.public_addr.map(|x| x.parse().unwrap()); - tokio::join!(netapp.listen(listen_addr, public_addr), peering.run(),); + tokio::join!( + netapp.listen(listen_addr, public_addr, watch_cancel.clone()), + peering.run(watch_cancel), + ); } -- cgit v1.2.3