mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-01 00:00:10 +02:00
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]>