Skip to content

Commit

Permalink
remove tokio spawn to potentially accomodate wasm32
Browse files Browse the repository at this point in the history
  • Loading branch information
jmwample committed Nov 6, 2024
1 parent 6f53b3a commit b57c224
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/client-core/src/client/base_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ where
stats_control.start_with_shutdown(shutdown.fork("statistics_control"));
stats_reporter
}
None => ClientStatsSender::sink(),
None => ClientStatsSender::sink(shutdown.fork("statistics_sink")),
}
}

Expand Down
3 changes: 2 additions & 1 deletion common/statistics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ si-scale = { workspace = true }

nym-sphinx = { path = "../nymsphinx" }
nym-credentials-interface = { path = "../credentials-interface" }
nym-metrics = { path = "../nym-metrics" }
nym-metrics = { path = "../nym-metrics" }
nym-task = { path = "../task" }
22 changes: 20 additions & 2 deletions common/statistics/src/clients/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

use crate::report::StatisticsReporter;
use nym_task::spawn;

use tokio::sync::mpsc::UnboundedSender;

Expand Down Expand Up @@ -37,9 +38,26 @@ impl ClientStatsSender {
}

/// Used when stats reporting is disabled -- reads all incoming messages and discards them
pub fn sink() -> Self {
pub fn sink(mut shutdown: nym_task::TaskClient) -> Self {
let (stats_tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
tokio::spawn(async move { while (rx.recv().await).is_some() {} });

spawn(async move {
loop {
tokio::select! {
m = rx.recv() => {
if m.is_none() {
log::trace!("StatisticsSink: channel closed shutting down");
break;
}
},
_ = shutdown.recv_with_delay() => {
log::trace!("StatisticsSink: Received shutdown");
break;
},
}
}
log::debug!("StatsSink: Exited");
});
Self { stats_tx }
}
}
Expand Down

0 comments on commit b57c224

Please sign in to comment.