From 958d3a9e27e603f38f3d8acb5908fbfa269469ca Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Sat, 28 Sep 2019 01:37:17 +0200 Subject: [PATCH] add an unstable `task::spawn_blocking` function Signed-off-by: Yoshua Wuyts --- src/task/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/task/mod.rs b/src/task/mod.rs index 9e92f35..41b65c4 100644 --- a/src/task/mod.rs +++ b/src/task/mod.rs @@ -48,3 +48,17 @@ mod task_local; mod worker; pub(crate) mod blocking; + +/// Spawns a blocking task. +/// +/// The task will be spawned onto a thread pool specifically dedicated to blocking tasks. +#[cfg(any(feature = "unstable", feature = "docs"))] +#[cfg_attr(feature = "docs", doc(cfg(unstable)))] +#[inline] +pub fn spawn_blocking(future: F) -> blocking::JoinHandle +where + F: crate::future::Future + Send + 'static, + R: Send + 'static, +{ + blocking::spawn(future) +}