tokio: adapt to 1.0 runtime changes

enter() now returns a guard, and the builder got revamped to make the
choice between MT and current thread explicit.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2020-12-04 09:42:23 +01:00
parent 484172b5f8
commit 5c852d5b82

View File

@ -84,8 +84,7 @@ pub fn get_runtime_with_builder<F: Fn() -> runtime::Builder>(get_builder: F) ->
pub fn get_runtime() -> Arc<Runtime> {
get_runtime_with_builder(|| {
let mut builder = runtime::Builder::new();
builder.threaded_scheduler();
let mut builder = runtime::Builder::new_multi_thread();
builder.enable_all();
builder
})
@ -122,7 +121,8 @@ pub fn block_on<F: Future>(fut: F) -> F::Output {
// not a worker thread, not associated with a runtime, make sure we have a runtime (spawn
// it on demand if necessary), then enter it
let _guard = BlockingGuard::set();
get_runtime().enter(move || block_on_local_future(fut))
let _enter_guard = get_runtime().enter();
get_runtime().block_on(fut)
}
}