async_std/task/
spawn_local.rs

1use std::future::Future;
2
3use crate::task::{Builder, JoinHandle};
4
5/// Spawns a task onto the thread-local executor.
6///
7/// # Examples
8///
9/// ```
10/// # #[cfg(feature = "unstable")]
11/// # async_std::task::block_on(async {
12/// #
13/// use async_std::task;
14///
15/// let handle = task::spawn_local(async {
16///     1 + 2
17/// });
18///
19/// assert_eq!(handle.await, 3);
20/// #
21/// # })
22/// ```
23#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
24#[inline]
25pub fn spawn_local<F, T>(future: F) -> JoinHandle<T>
26where
27    F: Future<Output = T> + 'static,
28    T: 'static,
29{
30    Builder::new().local(future).expect("cannot spawn task")
31}