14 releases

✓ Uses Rust 2018 edition

0.2.0-alpha.4 Aug 29, 2019
0.1.8 Jul 3, 2019
0.1.7 Mar 22, 2019
0.1.5 Sep 27, 2018
0.1.2 Mar 30, 2018

#4 in Concurrency

Download history 57976/week @ 2019-05-16 59894/week @ 2019-05-23 64216/week @ 2019-05-30 63796/week @ 2019-06-06 69469/week @ 2019-06-13 68340/week @ 2019-06-20 66583/week @ 2019-06-27 68358/week @ 2019-07-04 72902/week @ 2019-07-11 72908/week @ 2019-07-18 75697/week @ 2019-07-25 77110/week @ 2019-08-01 87112/week @ 2019-08-08 82941/week @ 2019-08-15 76543/week @ 2019-08-22

312,485 downloads per month
Used in 2,312 crates (62 directly)

MIT license

260KB
4.5K SLoC

tokio-executor

Task execution related traits and utilities.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Tokio by you, shall be licensed as MIT, without any additional terms or conditions.


lib.rs:

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 whenever the task is notified. Notification happens when the internal 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:

  • 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.

  • 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.

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 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.

Dependencies

~540KB