Skip to content

Commit

Permalink
task: clarify doc about tasks starting immediately (#5364)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn authored Jan 14, 2023
1 parent 40782ef commit 06f1a60
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 32 deletions.
6 changes: 3 additions & 3 deletions tokio/src/runtime/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ impl Handle {
/// thread pool. The thread pool is then responsible for polling the future
/// until it completes.
///
/// You do not have to `.await` the returned `JoinHandle` to make the
/// provided future start execution. It will start running in the background
/// immediately when `spawn` is called.
/// The provided future will start running in the background immediately
/// when `spawn` is called, even if you don't await the returned
/// `JoinHandle`.
///
/// See [module level][mod] documentation for more details.
///
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/runtime/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ impl Runtime {
/// thread pool. The thread pool is then responsible for polling the future
/// until it completes.
///
/// You do not have to `.await` the returned `JoinHandle` to make the
/// provided future start execution. It will start running in the
/// background immediately when `spawn` is called.
/// The provided future will start running in the background immediately
/// when `spawn` is called, even if you don't await the returned
/// `JoinHandle`.
///
/// See [module level][mod] documentation for more details.
///
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/runtime/task/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ cfg_rt! {
/// An owned permission to join on a task (await its termination).
///
/// This can be thought of as the equivalent of [`std::thread::JoinHandle`]
/// for a Tokio task rather than a thread. You do not need to `.await` the
/// `JoinHandle` to make the task execute — it will start running in the
/// background immediately.
/// for a Tokio task rather than a thread. Note that the background task
/// associated with this `JoinHandle` started running immediately when you
/// called spawn, even if you have not yet awaited the `JoinHandle`.
///
/// A `JoinHandle` *detaches* the associated task when it is dropped, which
/// means that there is no longer any handle to the task, and no way to `join`
Expand Down
24 changes: 11 additions & 13 deletions tokio/src/task/join_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ impl<T: 'static> JoinSet<T> {
/// Spawn the provided task on the `JoinSet`, returning an [`AbortHandle`]
/// that can be used to remotely cancel the task.
///
/// You do not have to `.await` the returned `JoinHandle` to make the
/// provided future start execution. It will start running in the background
/// immediately when `spawn` is called.
/// The provided future will start running in the background immediately
/// when this method is called, even if you don't await anything on this
/// `JoinSet`.
///
/// # Panics
///
Expand All @@ -143,9 +143,9 @@ impl<T: 'static> JoinSet<T> {
/// `JoinSet` returning an [`AbortHandle`] that can be used to remotely
/// cancel the task.
///
/// You do not have to `.await` the returned `JoinHandle` to make the
/// provided future start execution. It will start running in the background
/// immediately when `spawn_on` is called.
/// The provided future will start running in the background immediately
/// when this method is called, even if you don't await anything on this
/// `JoinSet`.
///
/// [`AbortHandle`]: crate::task::AbortHandle
#[track_caller]
Expand All @@ -162,9 +162,9 @@ impl<T: 'static> JoinSet<T> {
/// `JoinSet`, returning an [`AbortHandle`] that can be used to remotely
/// cancel the task.
///
/// You do not have to `.await` the returned `JoinHandle` to make the
/// provided future start execution. It will start running in the background
/// immediately when `spawn_local` is called.
/// The provided future will start running in the background immediately
/// when this method is called, even if you don't await anything on this
/// `JoinSet`.
///
/// # Panics
///
Expand All @@ -186,10 +186,8 @@ impl<T: 'static> JoinSet<T> {
/// remotely cancel the task.
///
/// Unlike the [`spawn_local`] method, this method may be used to spawn local
/// tasks when the `LocalSet` is _not_ running. You do not have to `.await`
/// the returned `JoinHandle` to make the provided future start execution.
/// It will start running immediately whenever the `LocalSet` is next
/// started.
/// tasks on a `LocalSet` that is _not_ currently running. The provided
/// future will start running whenever the `LocalSet` is next started.
///
/// [`LocalSet`]: crate::task::LocalSet
/// [`AbortHandle`]: crate::task::AbortHandle
Expand Down
13 changes: 6 additions & 7 deletions tokio/src/task/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ cfg_rt! {
///
/// The spawned future will run on the same thread that called `spawn_local`.
///
/// You do not have to `.await` the returned `JoinHandle` to make the
/// provided future start execution. It will start running in the background
/// immediately when `spawn_local` is called.
/// The provided future will start running in the background immediately
/// when `spawn_local` is called, even if you don't await the returned
/// `JoinHandle`.
///
/// # Panics
///
Expand Down Expand Up @@ -417,10 +417,9 @@ impl LocalSet {
/// This task is guaranteed to be run on the current thread.
///
/// Unlike the free function [`spawn_local`], this method may be used to
/// spawn local tasks when the `LocalSet` is _not_ running. You do not have
/// to `.await` the returned `JoinHandle` to make the provided future start
/// execution. It will start running immediately whenever the `LocalSet` is
/// next started.
/// spawn local tasks when the `LocalSet` is _not_ running. The provided
/// future will start running once the `LocalSet` is next started, even if
/// you don't await the returned `JoinHandle`.
///
/// # Examples
///
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/task/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ cfg_rt! {
/// Spawns a new asynchronous task, returning a
/// [`JoinHandle`](super::JoinHandle) for it.
///
/// You do not have to `.await` the returned `JoinHandle` to make the
/// provided future start execution. It will start running in the background
/// immediately when `spawn` is called.
/// The provided future will start running in the background immediately
/// when `spawn` is called, even if you don't await the returned
/// `JoinHandle`.
///
/// Spawning a task enables the task to execute concurrently to other tasks. The
/// spawned task may execute on the current thread, or it may be sent to a
Expand Down

0 comments on commit 06f1a60

Please sign in to comment.