moq_async/spawn.rs
1use std::future::Future;
2use tracing::Instrument;
3
4// It's not pretty, but we have per-platform implementations of spawn.
5// The main problem is Send; it's an annoying trait that colors everything.
6// The rest of this crate is Send agnostic so it will work on WASM.
7// TODO: use a send feature and make this runtime agnostic?
8
9#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
10pub fn spawn<F: Future<Output = ()> + Send + 'static>(f: F) {
11 tokio::task::spawn(f.in_current_span());
12}
13
14#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
15pub fn spawn<F: Future<Output = ()> + 'static>(f: F) {
16 wasm_bindgen_futures::spawn_local(f.in_current_span());
17}