- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.8k
          [0.1.x] add set_default to 0.1 executor, timer, and reactor
          #1725
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| The "Test async-await" CI failure seems unrelated? | 
| Could  I'm excited to see this PR! I have been thinking about building something like this to improve our libevent-tokio integration. This new API will allow us to have tokio defaults set when we are executing outside of a tokio context. (For context, we have a very large amount of C that runs outside of a tokio runtime context. This C code may call into Rust via FFI or callbacks. We must avoid calling tokio functions in these cases because the missing defaults will cause a panic.) | 
| @GeorgeHahn Yup, added  | 
| PR #1742 will fix the broken CI builds for this branch, which are unrelated to the rest of this change. When that branch merges, I'll rebase this one and merge it, unless there are any objections? | 
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 <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Using `try_with` prevents double panics from occurring when thread locals have already been destroyed Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
993cf0d    to
    4906d99      
    Compare
  
    Signed-off-by: Eliza Weisman <eliza@buoyant.io>
# 0.1.9 (November 7, 2019) ### Added - Add `executor::set_default` which behaves like `with_default` but returns a drop guard (#1725). Signed-off-by: Eliza Weisman <eliza@buoyant.io>
# 0.1.11 (November 7, 2019) ### Added - `set_default`, which functions like `with_default` but returns a drop guard (#1725) Signed-off-by: Eliza Weisman <eliza@buoyant.io>
# 0.1.9 (November 7, 2019) ### Added - Add `executor::set_default` which behaves like `with_default` but returns a drop guard (#1725). Signed-off-by: Eliza Weisman <eliza@buoyant.io>
# 0.1.11 (November 7, 2019) ### Added - `set_default`, which functions like `with_default` but returns a drop guard (#1725) Signed-off-by: Eliza Weisman <eliza@buoyant.io>
# 0.1.9 (November 7, 2019) ### Added - Add `executor::set_default` which behaves like `with_default` but returns a drop guard (#1725). Signed-off-by: Eliza Weisman <eliza@buoyant.io>
This commit adds
set_defaultdrop guard style APIs for setting thedefault reactor, executor, and timer. These are similar to the APIs used
in
tokio0.2In addition to having potentially better ergonomics than the
with_defaultclosure APIs, the drop-guard based APIs will be helpfulin rewriting the
tokio-compatcrate to wrap the existing tokio 0.2runtime, rather than constructing its own runtime.
Because the runtime does not expose an
around_workerAPI, it cannotcurrently be used with the 0.1
with_defaultmethod of setting thereactor, timer, and executor. This means that tokio-compat must
duplicate a lot of existing code from
tokioto 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_startandafter_stop, by storing the drop guards in a thread-local. This willallow
tokio-compatto 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 eliza@buoyant.io