diff options
author | Carl Lerche <me@carllerche.com> | 2019-12-01 12:49:38 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-01 12:49:38 -0800 |
commit | 8b60c5386a60be4dacffe71823350040e8ba90fd (patch) | |
tree | 5f030468b5d5a1018f4194ed24c8935d66f20f0c /tokio/src/task/spawn.rs | |
parent | af07f5bee72bc5c93ed1331cdba3a10f9ae7f569 (diff) |
doc: fix documented feature flags for tokio::task (#1876)
Some feature flags are missing and some are duplicated.
Closes #1836
Diffstat (limited to 'tokio/src/task/spawn.rs')
-rw-r--r-- | tokio/src/task/spawn.rs | 96 |
1 files changed, 49 insertions, 47 deletions
diff --git a/tokio/src/task/spawn.rs b/tokio/src/task/spawn.rs index e0d19fd5..ab1356c8 100644 --- a/tokio/src/task/spawn.rs +++ b/tokio/src/task/spawn.rs @@ -3,51 +3,53 @@ use crate::task::JoinHandle; use std::future::Future; -/// Spawns a new asynchronous task, returning a -/// [`JoinHandle`](super::JoinHandle) for it. -/// -/// 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. -/// -/// # Examples -/// -/// In this example, a server is started and `spawn` is used to start a new task -/// that processes each received connection. -/// -/// ```no_run -/// use tokio::net::{TcpListener, TcpStream}; -/// -/// use std::io; -/// -/// async fn process(socket: TcpStream) { -/// // ... -/// # drop(socket); -/// } -/// -/// #[tokio::main] -/// async fn main() -> io::Result<()> { -/// let mut listener = TcpListener::bind("127.0.0.1:8080").await?; -/// -/// loop { -/// let (socket, _) = listener.accept().await?; -/// -/// tokio::spawn(async move { -/// // Process each socket concurrently. -/// process(socket).await -/// }); -/// } -/// } -/// ``` -/// -/// # Panics -/// -/// Panics if called from **outside** of the Tokio runtime. -pub fn spawn<T>(task: T) -> JoinHandle<T::Output> -where - T: Future + Send + 'static, - T::Output: Send + 'static, -{ - runtime::spawn(task) +doc_rt_core! { + /// Spawns a new asynchronous task, returning a + /// [`JoinHandle`](super::JoinHandle) for it. + /// + /// 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. + /// + /// # Examples + /// + /// In this example, a server is started and `spawn` is used to start a new task + /// that processes each received connection. + /// + /// ```no_run + /// use tokio::net::{TcpListener, TcpStream}; + /// + /// use std::io; + /// + /// async fn process(socket: TcpStream) { + /// // ... + /// # drop(socket); + /// } + /// + /// #[tokio::main] + /// async fn main() -> io::Result<()> { + /// let mut listener = TcpListener::bind("127.0.0.1:8080").await?; + /// + /// loop { + /// let (socket, _) = listener.accept().await?; + /// + /// tokio::spawn(async move { + /// // Process each socket concurrently. + /// process(socket).await + /// }); + /// } + /// } + /// ``` + /// + /// # Panics + /// + /// Panics if called from **outside** of the Tokio runtime. + pub fn spawn<T>(task: T) -> JoinHandle<T::Output> + where + T: Future + Send + 'static, + T::Output: Send + 'static, + { + runtime::spawn(task) + } } |