quickjs_runtime/jsutils/
helper_tasks.rs1use futures::Future;
2use hirofa_utils::task_manager::TaskManager;
3use lazy_static::lazy_static;
4use tokio::task::JoinError;
5
6lazy_static! {
7 static ref HELPER_TASKS: TaskManager = TaskManager::new(std::cmp::max(2, num_cpus::get()));
9}
10
11pub fn add_helper_task<T>(task: T)
13where
14 T: FnOnce() + Send + 'static,
15{
16 log::trace!("adding a helper task");
17 HELPER_TASKS.add_task(task);
18}
19
20pub fn add_helper_task_async<R: Send + 'static, T: Future<Output = R> + Send + 'static>(
22 task: T,
23) -> impl Future<Output = Result<R, JoinError>> {
24 log::trace!("adding an async helper task");
25 HELPER_TASKS.add_task_async(task)
26}