jobs: add spawn_blocking() method

async
Manos Pitsidianakis 2020-07-16 22:53:16 +03:00
parent 1f9cdb8be5
commit eb62463e7d
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 8 additions and 0 deletions

View File

@ -214,6 +214,14 @@ impl JobExecutor {
(receiver, JoinHandle(handle), job_id)
}
pub fn spawn_blocking<F, R>(&self, future: F) -> (oneshot::Receiver<R>, JoinHandle, JobId)
where
F: Future<Output = R> + Send + 'static,
R: Send + 'static,
{
self.spawn_specialized(smol::Task::blocking(async move { future.await }))
}
}
pub type JobChannel<T> = oneshot::Receiver<Result<T>>;