1#[cfg(all(not(target_arch = "wasm32"), feature = "threaded"))]
33pub fn run_future<F: std::future::Future<Output = ()> + Send + 'static>(future: F) {
34 use std::thread;
35
36 thread::spawn(move || {
37 let rt = tokio::runtime::Builder::new_current_thread()
38 .enable_all()
39 .build()
40 .expect("Failed to create runtime");
41
42 rt.block_on(future);
43 })
44 .join()
45 .expect("Thread panicked");
46}
47
48#[cfg(all(not(target_arch = "wasm32"), not(feature = "threaded")))]
49pub fn run_future<F: std::future::Future<Output = ()> + 'static>(future: F) {
50 #[cfg(feature = "block")]
52 futures::executor::block_on(future);
53
54 #[cfg(not(feature = "block"))]
55 {
56 let mut local_pool = futures::executor::LocalPool::new();
57 use futures::task::LocalSpawnExt;
58 let spawner = local_pool.spawner();
59 spawner.spawn_local(future).expect("Failed to spawn future");
60 local_pool.run();
61 }
62}
63
64#[cfg(target_arch = "wasm32")]
65pub fn run_future<F: std::future::Future<Output = ()> + 'static>(future: F) {
66 wasm_bindgen_futures::spawn_local(future);
68}