use cfg_if::cfg_if;
use std::future::Future;
cfg_if! {
if #[cfg(all(feature = "tokio", target_os = "linux"))] {
pub(crate) fn block_on<F: Future>(future: F) -> F::Output {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_io()
.enable_time()
.build()
.expect("launch of single-threaded tokio runtime");
runtime.block_on(future)
}
} else if #[cfg(all(feature = "async-io", target_os = "linux"))] {
pub(crate) fn block_on<F: Future>(future: F) -> F::Output {
async_io::block_on(future)
}
} else if #[cfg(not(all(target_family = "wasm", target_os = "unknown")))] {
pub(crate) fn block_on<F: Future>(future: F) -> F::Output {
beul::execute(future)
}
}
}
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
pub(crate) fn spawn_future(future: impl Future<Output = ()> + Send + 'static) {
wasm_bindgen_futures::spawn_local(future);
}
#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
pub(crate) fn spawn_future(future: impl Future<Output = ()> + Send + 'static) {
std::thread::Builder::new()
.name(format!("{} subscription thread", env!("CARGO_PKG_NAME")))
.spawn(move || block_on(future))
.expect("failed to spawn thread");
}