Skip to content

Document task::spawn's support for blocking tasks. #906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/task/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ use crate::task::{Builder, JoinHandle};
/// #
/// # })
/// ```
///
/// # Blocking
///
/// It is fine to use `spawn` to start tasks that may carry out long-running
/// computations, use blocking I/O primitives, or otherwise engage in activities
/// that mean that polling the task's future may not always return quickly.
///
/// This function begins executing the given future on a thread pool shared with
/// other asynchronous tasks. If polling a particular task takes too long, that
/// thread is removed from the general pool and assigned to run that task
/// exclusively. A new thread is created to take its place in the general pool.
///
/// Although the usual expectation in asynchronous programming is that polling a
/// future should return quickly, in practice it can be hard to anticipate how a
/// given task will behave. A computation that has the potential to take a long
/// time might return quickly in practice, and vice versa. The `spawn` function
/// observes each task's behavior and chooses dynamically whether to assign it a
/// dedicated thread or let it share the thread pool with other tasks.
pub fn spawn<F, T>(future: F) -> JoinHandle<T>
where
F: Future<Output = T> + Send + 'static,
Expand Down