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