Files
tokio/tokio-executor/src/lib.rs
T

69 lines
2.7 KiB
Rust
Raw Normal View History

2018-08-24 08:58:26 -07:00
#![deny(missing_docs, missing_debug_implementations, warnings)]
2019-01-06 23:25:55 -08:00
#![doc(html_root_url = "https://docs.rs/tokio-executor/0.1.6")]
2018-08-24 08:58:26 -07:00
//! Task execution related traits and utilities.
//!
//! In the Tokio execution model, futures are lazy. When a future is created, no
//! work is performed. In order for the work defined by the future to happen,
//! the future must be submitted to an executor. A future that is submitted to
//! an executor is called a "task".
//!
//! The executor is responsible for ensuring that [`Future::poll`] is called
2018-07-11 20:30:51 +01:00
//! whenever the task is notified. Notification happens when the internal
2018-07-22 13:35:30 -07:00
//! state of a task transitions from *not ready* to *ready*. For example, a
//! socket might have received data and a call to `read` will now be able to
//! succeed.
//!
//! This crate provides traits and utilities that are necessary for building an
//! executor, including:
//!
2019-03-21 14:30:18 -07:00
//! * The [`Executor`] trait spawns future object onto an executor.
//!
//! * The [`TypedExecutor`] trait spawns futures of a specific type onto an
//! executor. This is used to be generic over executors that spawn futures
//! that are either `Send` or `!Send` or implement executors that apply to
//! specific futures.
//!
2018-08-25 15:26:41 -04:00
//! * [`enter`] marks that the current thread is entering an execution
//! context. This prevents a second executor from accidentally starting from
//! within the context of one that is already running.
//!
//! * [`DefaultExecutor`] spawns tasks onto the default executor for the current
//! context.
//!
//! * [`Park`] abstracts over blocking and unblocking the current thread.
//!
2019-03-21 14:30:18 -07:00
//! # Implementing an executor
//!
//! Executors should always implement `TypedExecutor`. This usually is the bound
//! that applications and libraries will use when generic over an executor. See
//! the [trait documentation][`TypedExecutor`] for more details.
//!
//! If the executor is able to spawn all futures that are `Send`, then the
//! executor should also implement the `Executor` trait. This trait is rarely
//! used directly by applications and libraries. Instead, `tokio::spawn` is
//! configured to dispatch to type that implements `Executor`.
//!
//! [`Executor`]: trait.Executor.html
2019-03-21 14:30:18 -07:00
//! [`TypedExecutor`]: trait.TypedExecutor.html
//! [`enter`]: fn.enter.html
//! [`DefaultExecutor`]: struct.DefaultExecutor.html
//! [`Park`]: park/index.html
2018-07-22 13:35:30 -07:00
//! [`Future::poll`]: https://docs.rs/futures/0.1/futures/future/trait.Future.html#tymethod.poll
2019-01-03 06:51:22 +01:00
extern crate crossbeam_utils;
extern crate futures;
mod enter;
2019-03-21 14:30:18 -07:00
mod error;
mod executor;
mod global;
pub mod park;
2019-03-21 14:30:18 -07:00
mod typed;
pub use enter::{enter, Enter, EnterError};
2019-03-21 14:30:18 -07:00
pub use error::SpawnError;
pub use executor::Executor;
pub use global::{spawn, with_default, DefaultExecutor};
2019-03-21 14:30:18 -07:00
pub use typed::TypedExecutor;