web_async/
spawn.rs

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