Skip to content

Commit

Permalink
get rid of spawn, improve docs for spawn_local
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah-Kennedy committed Sep 10, 2024
1 parent 39dc149 commit a57f0ed
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions tokio/src/runtime/local_runtime/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ impl LocalRuntime {
&self.handle
}

/// Spawns a future onto the `LocalRuntime`.
/// Spawns a task which isn't `Send + Sync` on the runtime.
///
/// See the documentation for the equivalent method on [Runtime] for more information
/// This is analogous to the [spawn] method on the standard [Runtime].
///
/// [Runtime]: crate::runtime::Runtime::spawn
/// [spawn]: crate::runtime::Runtime::spawn
/// [Runtime]: crate::runtime::Runtime
///
/// # Examples
///
Expand All @@ -127,26 +128,12 @@ impl LocalRuntime {
/// let rt = LocalRuntime::new().unwrap();
///
/// // Spawn a future onto the runtime
/// rt.spawn(async {
/// rt.spawn_local(async {
/// println!("now running on a worker thread");
/// });
/// # }
/// ```
#[track_caller]
pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
where
F: Future + Send + 'static,
F::Output: Send + 'static,
{
if cfg!(debug_assertions) && std::mem::size_of::<F>() > BOX_FUTURE_THRESHOLD {
self.handle.spawn_named(Box::pin(future), None)
} else {
self.handle.spawn_named(future, None)
}
}

/// Spawns a task which isn't `Send + Sync` on the runtime.
#[track_caller]
pub fn spawn_local<F>(&self, future: F) -> JoinHandle<F::Output>
where
F: Future + 'static,
Expand Down

0 comments on commit a57f0ed

Please sign in to comment.