|
|
@ -51,7 +51,29 @@ pub(crate) mod blocking;
|
|
|
|
|
|
|
|
|
|
|
|
/// Spawns a blocking task.
|
|
|
|
/// Spawns a blocking task.
|
|
|
|
///
|
|
|
|
///
|
|
|
|
/// The task will be spawned onto a thread pool specifically dedicated to blocking tasks.
|
|
|
|
/// The task will be spawned onto a thread pool specifically dedicated to blocking tasks. This
|
|
|
|
|
|
|
|
/// is useful to prevent long-running synchronous operations from blocking the main futures
|
|
|
|
|
|
|
|
/// executor.
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// See also: [`task::block_on`].
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// [`task::block_on`]: fn.block_on.html
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// # Examples
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// Basic usage:
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
|
|
|
|
/// # fn main() { async_std::task::block_on(async {
|
|
|
|
|
|
|
|
/// #
|
|
|
|
|
|
|
|
/// use async_std::task;
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
/// task::blocking(async {
|
|
|
|
|
|
|
|
/// println!("long-running task here");
|
|
|
|
|
|
|
|
/// }).await;
|
|
|
|
|
|
|
|
/// #
|
|
|
|
|
|
|
|
/// # }) }
|
|
|
|
|
|
|
|
/// ```
|
|
|
|
// Once this function stabilizes we should merge `blocking::spawn` into this so
|
|
|
|
// Once this function stabilizes we should merge `blocking::spawn` into this so
|
|
|
|
// all code in our crate uses `task::blocking` too.
|
|
|
|
// all code in our crate uses `task::blocking` too.
|
|
|
|
#[cfg(any(feature = "unstable", feature = "docs"))]
|
|
|
|
#[cfg(any(feature = "unstable", feature = "docs"))]
|
|
|
|