1 //! Tasks used to drive a future computation
2 //!
3 //! It's intended over time a particular operation (such as servicing an HTTP
4 //! request) will involve many futures. This entire operation, however, can be
5 //! thought of as one unit, as the entire result is essentially just moving
6 //! through one large state machine.
7 //!
8 //! A "task" is the unit of abstraction for what is driving this state machine
9 //! and tree of futures forward. A task is used to poll futures and schedule
10 //! futures with, and has utilities for sharing data between tasks and handles
11 //! for notifying when a future is ready. Each task also has its own set of
12 //! task-local data generated by `task_local!`.
13 //!
14 //! Note that libraries typically should not manage tasks themselves, but rather
15 //! leave that to event loops and other "executors" (see the `executor` module),
16 //! or by using the `wait` method to create and execute a task directly on the
17 //! current thread.
18 //!
19 //! More information about the task model can be found [online at tokio.rs].
20 //!
21 //! [online at tokio.rs]: https://tokio.rs/docs/going-deeper-futures/futures-model/
22 //!
23 //! ## Functions
24 //!
25 //! There is an important bare function in this module: `current`. The
26 //! `current` function returns a handle to the currently running task, panicking
27 //! if one isn't present. This handle is then used to later notify the task that
28 //! it's ready to make progress through the `Task::notify` method.
29 
30 #[doc(hidden)]
31 #[deprecated(since = "0.1.4", note = "import through the executor module instead")]
32 #[cfg(all(feature = "with-deprecated", feature = "use_std"))]
33 #[allow(deprecated)]
34 pub use task_impl::{Spawn, spawn, Unpark, Executor, Run, park};
35 
36 pub use task_impl::{Task, AtomicTask, current, init};
37 
38 #[allow(deprecated)]
39 #[cfg(feature = "use_std")]
40 pub use task_impl::{LocalKey, with_unpark_event, UnparkEvent, EventSet};
41 
42 #[doc(hidden)]
43 #[deprecated(since = "0.1.4", note = "import through the executor module instead")]
44 #[cfg(all(feature = "with-deprecated", feature = "use_std"))]
45 #[allow(deprecated)]
46 pub use task_impl::TaskRc;
47