Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8e6dbb5
feat: clarify spawn call
Its-Just-Nans Dec 29, 2025
051623b
Update tokio/src/runtime/runtime.rs
Its-Just-Nans Dec 29, 2025
924d772
update sentence
Its-Just-Nans Dec 29, 2025
dede762
fix CI
Its-Just-Nans Dec 29, 2025
f2ab9df
Update tokio/src/runtime/runtime.rs
Its-Just-Nans Dec 29, 2025
02a5ce9
fix link
Its-Just-Nans Dec 29, 2025
dc7a2ce
Merge branch 'change-doc-sentence' of github.com:Its-Just-Nans/tokio …
Its-Just-Nans Dec 29, 2025
52a2cc3
Update tokio/src/runtime/handle.rs
Its-Just-Nans Dec 30, 2025
14bfb82
Update tokio/src/task/spawn.rs
Its-Just-Nans Dec 30, 2025
25e30be
Update tokio/src/task/spawn.rs
Its-Just-Nans Dec 30, 2025
9a08f17
Update tokio/src/task/spawn.rs
Its-Just-Nans Dec 30, 2025
fbcd157
Update tokio/src/runtime/runtime.rs
Its-Just-Nans Dec 30, 2025
3063480
Update tokio/src/runtime/runtime.rs
Its-Just-Nans Dec 30, 2025
19976ba
fix doc link for runtime
Its-Just-Nans Jan 1, 2026
7a8cb70
try new docs
Its-Just-Nans Jan 2, 2026
33b05d9
add https://github.com/tokio-rs/tokio/pull/7803#issuecomment-3703940381
Its-Just-Nans Jan 2, 2026
f8b168d
spellcheck
Its-Just-Nans Jan 2, 2026
2c80c10
fmt
Its-Just-Nans Jan 2, 2026
66496ef
change docs
Its-Just-Nans Jan 3, 2026
cefed98
spellcheck
Its-Just-Nans Jan 3, 2026
531b492
spelling
Its-Just-Nans Jan 3, 2026
ab1bf79
Update tokio/src/runtime/handle.rs
Its-Just-Nans Jan 24, 2026
a705a47
add
Its-Just-Nans Jan 24, 2026
9a27185
fix doc
Its-Just-Nans Jan 29, 2026
37f51a1
change wording
Its-Just-Nans Feb 4, 2026
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
3 changes: 2 additions & 1 deletion tokio/src/runtime/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ impl Handle {
///
/// The provided future will start running in the background immediately
/// when `spawn` is called, even if you don't await the returned
/// `JoinHandle`.
/// `JoinHandle` (assuming that the runtime [is running][running-runtime]).
///
/// See [module level][mod] documentation for more details.
///
/// [mod]: index.html
/// [running-runtime]: index.html#driving-the-runtime
///
/// # Examples
///
Expand Down
19 changes: 19 additions & 0 deletions tokio/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,25 @@
//! This is done with [`Builder::enable_io`] and [`Builder::enable_time`]. As a
//! shorthand, [`Builder::enable_all`] enables both resource drivers.
//!
//! ## Driving the runtime
//!
//! A Tokio runtime can only execute tasks if the runtime is running. Normally
//! this is not an issue as the default configuration of a runtime is always running,
//! but alternate configurations such as the current-thread runtime require that
//! [`Runtime::block_on`] is called.
//!
//! - A multi-threaded runtime is always running because it spawns its own worker
//! threads.
//! - A current-thread runtime does not spawn any worker threads, so it can only
//! execute tasks when you provide a thread by calling [`Runtime::block_on`].
//! - A [`LocalSet`](crate::task::LocalSet) only executes local tasks spawned on
//! it when the `LocalSet` is `.awaited` or otherwise driven using one of its
//! methods for this purpose.
//!
//! Please be aware that [`Handle::block_on`] does not drive the runtime.
//! There must be at least one call to [`Runtime::block_on`] when using the current
//! thread runtime. [`Handle::block_on`] is not enough.
//!
//! ## Lifetime of spawned threads
//!
//! The runtime may spawn threads depending on its configuration and usage. The
Expand Down
3 changes: 2 additions & 1 deletion tokio/src/runtime/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,12 @@ impl Runtime {
///
/// The provided future will start running in the background immediately
/// when `spawn` is called, even if you don't await the returned
/// `JoinHandle`.
/// `JoinHandle` (assuming that the runtime [is running][running-runtime]).
///
/// See [module level][mod] documentation for more details.
///
/// [mod]: index.html
/// [running-runtime]: index.html#driving-the-runtime
///
/// # Examples
///
Expand Down
11 changes: 8 additions & 3 deletions tokio/src/task/spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ use std::future::Future;

cfg_rt! {
/// Spawns a new asynchronous task, returning a
/// [`JoinHandle`](JoinHandle) for it.
/// [`JoinHandle`] for it.
///
/// The provided future will start running in the background immediately
/// when `spawn` is called, even if you don't await the returned
/// `JoinHandle`.
/// [`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
/// different thread to be executed. The specifics depend on the current
/// [`Runtime`](crate::runtime::Runtime) configuration.
/// [`Runtime`](crate::runtime::Runtime) configuration. In a
/// [running runtime][running-runtime], the task will start immediately in the
/// background. On a blocked runtime, the user must drive the runtime forward (for
/// example, by calling [`Runtime::block_on`](crate::runtime::Runtime::block_on)).
///
/// It is guaranteed that spawn will not synchronously poll the task being spawned.
/// This means that calling spawn while holding a lock does not pose a risk of
Expand All @@ -29,6 +32,8 @@ cfg_rt! {
/// the Tokio runtime are always inside its context, but you can also enter the context
/// using the [`Runtime::enter`](crate::runtime::Runtime::enter()) method.
///
/// [running-runtime]: ../runtime/index.html#driving-the-runtime
///
/// # Examples
///
/// In this example, a server is started and `spawn` is used to start a new task
Expand Down
Loading