This commit adds `set_default` drop guard style APIs for setting the default reactor, executor, and timer. These are similar to the APIs used in `tokio` 0.2 In addition to having potentially better ergonomics than the `with_default` closure APIs, the drop-guard based APIs will be helpful in rewriting the `tokio-compat` crate to wrap the existing tokio 0.2 runtime, rather than constructing its own runtime. Because the runtime does not expose an `around_worker` API, it cannot currently be used with the 0.1 `with_default` method of setting the reactor, timer, and executor. This means that tokio-compat must duplicate a lot of existing code from `tokio` to construct the runtime, which is unfortunate (and has the potential to introduce errors). On the other hand, we can use the drop guard APIs with `before_start` and `after_stop`, by storing the drop guards in a thread-local. This will allow `tokio-compat` to wrap the 0.2 runtime, reducing code duplication. Also, this will allow the blocking pool to be used on the compat runtime, which is currently impossible (as the blocking APIs are private to `tokio`). Signed-off-by: Eliza Weisman <[email protected]>
tokio-reactor
Event loop that drives Tokio I/O resources.
Overview
The reactor is the engine that drives asynchronous I/O resources (like TCP and
UDP sockets). It is backed by mio and acts as a bridge between mio and
futures.
The crate provides:
-
Reactoris the main type of this crate. It performs the event loop logic. -
Handleprovides a reference to a reactor instance. -
RegistrationandPollEventedallow third parties to implement I/O resources that are driven by the reactor.
Application authors will not use this crate directly. Instead, they will use the
tokio crate. Library authors should only depend on tokio-reactor if they
are building a custom I/O resource.
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.