mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-08 00:00:13 +02:00
task: add example for spawn_local usage on local runtime (#7689)
This commit is contained in:
@@ -353,6 +353,8 @@ cfg_rt! {
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
/// With `LocalSet`:
|
||||||
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use std::rc::Rc;
|
/// use std::rc::Rc;
|
||||||
/// use tokio::task;
|
/// use tokio::task;
|
||||||
@@ -373,10 +375,27 @@ cfg_rt! {
|
|||||||
/// }).await;
|
/// }).await;
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
/// With local runtime flavor ([Unstable API][unstable] only).
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # #[cfg(tokio_unstable)]
|
||||||
|
/// #[tokio::main(flavor = "local")]
|
||||||
|
/// async fn main() {
|
||||||
|
/// let join = tokio::task::spawn_local(async {
|
||||||
|
/// println!("my nonsend data...")
|
||||||
|
/// });
|
||||||
|
///
|
||||||
|
/// join.await.unwrap()
|
||||||
|
/// }
|
||||||
|
/// # #[cfg(not(tokio_unstable))]
|
||||||
|
/// # fn main() {}
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
///
|
///
|
||||||
/// [`LocalSet`]: struct@crate::task::LocalSet
|
/// [`LocalSet`]: struct@crate::task::LocalSet
|
||||||
/// [`LocalRuntime`]: struct@crate::runtime::LocalRuntime
|
/// [`LocalRuntime`]: struct@crate::runtime::LocalRuntime
|
||||||
/// [`tokio::spawn`]: fn@crate::task::spawn
|
/// [`tokio::spawn`]: fn@crate::task::spawn
|
||||||
|
/// [unstable]: ../../tokio/index.html#unstable-features
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn spawn_local<F>(future: F) -> JoinHandle<F::Output>
|
pub fn spawn_local<F>(future: F) -> JoinHandle<F::Output>
|
||||||
where
|
where
|
||||||
|
|||||||
Reference in New Issue
Block a user