From a9df5da39c41286aceb6267f96a88670674c8a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Thu, 17 Aug 2023 12:21:15 +0100 Subject: [PATCH] removed redundant notify and instead awaiting the task futures --- .../parallel_sending_and_receiving.rs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/sdk/rust/nym-sdk/examples/parallel_sending_and_receiving.rs b/sdk/rust/nym-sdk/examples/parallel_sending_and_receiving.rs index 4c048e27ae..ca9b843717 100644 --- a/sdk/rust/nym-sdk/examples/parallel_sending_and_receiving.rs +++ b/sdk/rust/nym-sdk/examples/parallel_sending_and_receiving.rs @@ -4,8 +4,6 @@ use futures::StreamExt; use nym_sdk::mixnet; use nym_sdk::mixnet::MixnetMessageSender; -use std::sync::Arc; -use tokio::sync::Notify; #[tokio::main] async fn main() { @@ -18,36 +16,27 @@ async fn main() { let our_address = *client.nym_address(); println!("Our client nym address is: {our_address}"); - let receive_notify = Arc::new(Notify::new()); - let receive_notify2 = receive_notify.clone(); - let send_notify = Arc::new(Notify::new()); - let send_notify2 = send_notify.clone(); - let sender = client.split_sender(); // receiving task - tokio::spawn(async move { + let receiving_task_handle = tokio::spawn(async move { if let Some(received) = client.next().await { println!("Received: {}", String::from_utf8_lossy(&received.message)); } client.disconnect().await; - // notify that we're done and leave the task! - receive_notify.notify_waiters(); }); // sending task - tokio::spawn(async move { + let sending_task_handle = tokio::spawn(async move { sender .send_plain_message(our_address, "hello from a different task!") .await .unwrap(); - - send_notify.notify_waiters(); }); // wait for both tasks to be done println!("waiting for shutdown"); - send_notify2.notified().await; - receive_notify2.notified().await; + sending_task_handle.await.unwrap(); + receiving_task_handle.await.unwrap(); }