mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-28 00:00:11 +02:00
task: clarify the behavior of several spawn_local methods (#7669)
This commit is contained in:
@@ -345,8 +345,8 @@ where
|
||||
self.insert(key, task);
|
||||
}
|
||||
|
||||
/// Spawn the provided task on the current [`LocalSet`] and store it in this
|
||||
/// `JoinMap` with the provided key.
|
||||
/// Spawn the provided task on the current [`LocalSet`] or [`LocalRuntime`]
|
||||
/// and store it in this `JoinMap` with the provided key.
|
||||
///
|
||||
/// If a task previously existed in the `JoinMap` for this key, that task
|
||||
/// will be cancelled and replaced with the new one. The previous task will
|
||||
@@ -355,9 +355,10 @@ where
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This method panics if it is called outside of a `LocalSet`.
|
||||
/// This method panics if it is called outside of a `LocalSet` or `LocalRuntime`.
|
||||
///
|
||||
/// [`LocalSet`]: tokio::task::LocalSet
|
||||
/// [`LocalRuntime`]: tokio::runtime::LocalRuntime
|
||||
/// [`join_next`]: Self::join_next
|
||||
#[track_caller]
|
||||
pub fn spawn_local<F>(&mut self, key: K, task: F)
|
||||
|
||||
@@ -88,9 +88,9 @@ impl<T> JoinQueue<T> {
|
||||
self.push_back(handle.spawn(task))
|
||||
}
|
||||
|
||||
/// Spawn the provided task on the current [`LocalSet`] and store it in this
|
||||
/// [`JoinQueue`], returning an [`AbortHandle`] that can be used to remotely
|
||||
/// cancel the task.
|
||||
/// Spawn the provided task on the current [`LocalSet`] or [`LocalRuntime`]
|
||||
/// and store it in this [`JoinQueue`], returning an [`AbortHandle`] that
|
||||
/// can be used to remotely cancel the task.
|
||||
///
|
||||
/// The provided future will start running in the background immediately
|
||||
/// when this method is called, even if you don't await anything on this
|
||||
@@ -98,9 +98,10 @@ impl<T> JoinQueue<T> {
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This method panics if it is called outside of a `LocalSet`.
|
||||
/// This method panics if it is called outside of a `LocalSet` or `LocalRuntime`.
|
||||
///
|
||||
/// [`LocalSet`]: tokio::task::LocalSet
|
||||
/// [`LocalRuntime`]: tokio::runtime::LocalRuntime
|
||||
/// [`AbortHandle`]: tokio::task::AbortHandle
|
||||
#[track_caller]
|
||||
pub fn spawn_local<F>(&mut self, task: F) -> AbortHandle
|
||||
|
||||
@@ -401,11 +401,17 @@ impl TaskTracker {
|
||||
handle.spawn(self.track_future(task))
|
||||
}
|
||||
|
||||
/// Spawn the provided future on the current [`LocalSet`], and track it in this `TaskTracker`.
|
||||
/// Spawn the provided future on the current [`LocalSet`] or [`LocalRuntime`]
|
||||
/// and track it in this `TaskTracker`.
|
||||
///
|
||||
/// This is equivalent to `tokio::task::spawn_local(tracker.track_future(task))`.
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// This method panics if it is called outside of a `LocalSet` or `LocalRuntime`.
|
||||
///
|
||||
/// [`LocalSet`]: tokio::task::LocalSet
|
||||
/// [`LocalRuntime`]: tokio::runtime::LocalRuntime
|
||||
#[inline]
|
||||
#[track_caller]
|
||||
#[cfg(feature = "rt")]
|
||||
|
||||
Reference in New Issue
Block a user