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
23pub fn block_on<O>(fut: impl Future<Output = O>) -> O {
25 #[cfg(target_family = "wasm")]
26 {
27 super::reader::read_sync(fut)
28 }
29
30 #[cfg(all(not(target_family = "wasm"), not(feature = "std")))]
31 {
32 embassy_futures::block_on(fut)
33 }
34
35 #[cfg(all(not(target_family = "wasm"), feature = "std"))]
36 {
37 futures_lite::future::block_on(fut)
38 }
39}