use std::future::Future;
#[cfg(not(target_arch = "wasm32"))]
pub fn queue_microtask(task: impl FnOnce()) {
task();
}
#[cfg(target_arch = "wasm32")]
pub fn queue_microtask(task: impl FnOnce() + 'static) {
microtask(wasm_bindgen::closure::Closure::once_into_js(task));
}
#[cfg(target_arch = "wasm32")]
#[wasm_bindgen::prelude::wasm_bindgen(
inline_js = "export function microtask(f) { queueMicrotask(f); }"
)]
extern "C" {
fn microtask(task: wasm_bindgen::JsValue);
}
#[cfg(any(feature = "csr", feature = "hydrate"))]
pub fn spawn_local<F>(fut: F)
where
F: Future<Output = ()> + 'static,
{
wasm_bindgen_futures::spawn_local(fut)
}
#[cfg(not(any(feature = "csr", feature = "hydrate")))]
pub fn spawn_local<F>(fut: F)
where
F: Future<Output = ()> + 'static,
{
tokio::task::spawn_local(fut);
}
#[cfg(not(any(feature = "csr", feature = "hydrate", feature = "ssr")))]
pub fn spawn_local<F>(_fut: F)
where
F: Future<Output = ()> + 'static,
{
log::debug!("(spawn_local) no async runtime enabled; use features `csr`, `hydrate`, or `ssr`");
}