#[cfg(all(not(target_arch = "wasm32"), feature = "threaded"))]
pub fn run_future<F: std::future::Future<Output = ()> + Send + 'static>(future: F) {
use std::thread;
thread::spawn(move || {
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("Failed to create runtime");
rt.block_on(future);
})
.join()
.expect("Thread panicked");
}
#[cfg(all(not(target_arch = "wasm32"), not(feature = "threaded")))]
pub fn run_future<F: std::future::Future<Output = ()> + 'static>(future: F) {
#[cfg(feature = "block")]
futures::executor::block_on(future);
#[cfg(not(feature = "block"))]
{
let mut local_pool = futures::executor::LocalPool::new();
use futures::task::LocalSpawnExt;
let spawner = local_pool.spawner();
spawner.spawn_local(future).expect("Failed to spawn future");
local_pool.run();
}
}
#[cfg(target_arch = "wasm32")]
pub fn run_future<F: std::future::Future<Output = ()> + 'static>(future: F) {
wasm_bindgen_futures::spawn_local(future);
}