use async_executor::LocalExecutor;
pub(super) fn get_local_executor() -> &'static LocalExecutor<'static> {
thread_local! {
static EXECUTOR: LocalExecutor = const { LocalExecutor::new() };
}
EXECUTOR.with(|ex| {
unsafe { std::mem::transmute(ex) }
})
}
#[cfg(feature = "signals")]
pub fn new_local_task<T: 'static>(future: impl Future<Output = T> + 'static) {
use super::task_tracker::get_local_tracker;
let guard = get_local_tracker().track();
get_local_executor()
.spawn(async {
let _guard = guard;
future.await
})
.detach();
}
#[cfg(not(feature = "signals"))]
pub fn new_local_task<T: 'static>(future: impl Future<Output = T> + 'static) {
get_local_executor().spawn(future).detach();
}