1use alloc::boxed::Box;
2use core::{future::Future, pin::Pin};
3
4pub type DynFut<T> = Pin<Box<dyn Future<Output = T> + Send>>;
7
8pub fn spawn_detached_fut(fut: impl Future<Output = ()> + Send + 'static) {
11 cfg_if::cfg_if! {
12 if #[cfg(target_family = "wasm")] {
13 wasm_bindgen_futures::spawn_local(fut);
14 } else if #[cfg(feature = "std")] {
15 std::thread::spawn(|| block_on(fut));
16 } else {
17 drop(fut); panic!("spawn_detached_fut is only supported with 'std' or on 'wasm' targets");
19 }
20 }
21}
22
23#[cfg_attr(feature = "tracing", tracing::instrument(skip(fut)))]
25#[cfg_attr(feature = "std", allow(clippy::needless_lifetimes))]
26pub fn block_on<O>(fut: impl Future<Output = O>) -> O {
27 #[cfg(target_family = "wasm")]
28 {
29 super::reader::read_sync(fut)
30 }
31
32 #[cfg(all(not(target_family = "wasm"), not(feature = "std")))]
33 {
34 embassy_futures::block_on(fut)
35 }
36
37 #[cfg(all(not(target_family = "wasm"), feature = "std"))]
38 {
39 futures_lite::future::block_on(fut)
40 }
41}