Files
nym/common/task/src/spawn.rs
T
Jon Häggblad b694e675e6 clients: further deduplicate init code (#1873)
* client-core: move init helpers to module

* WIP

* socks5: return error instead of terminate in init

* Extract out reuse_existing_gateway_config

* rustfmt

* Remove comment out code

* nym-connect: use setup_gateway

* Linebreak

* changelog: update

* Tweak log

* rustfmt
2022-12-09 16:12:30 +01:00

34 lines
782 B
Rust

use crate::ShutdownListener;
use std::future::Future;
#[cfg(target_arch = "wasm32")]
pub(crate) fn spawn<F>(future: F)
where
F: Future<Output = ()> + 'static,
{
wasm_bindgen_futures::spawn_local(future);
}
#[cfg(not(target_arch = "wasm32"))]
pub(crate) fn spawn<F>(future: F)
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
tokio::spawn(future);
}
pub fn spawn_with_report_error<F, T, E>(future: F, mut shutdown: ShutdownListener)
where
F: Future<Output = Result<T, E>> + Send + 'static,
T: 'static,
E: std::error::Error + Send + Sync + 'static,
{
let future_that_sends = async move {
if let Err(err) = future.await {
shutdown.send_we_stopped(Box::new(err));
}
};
spawn(future_that_sends);
}