mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-31 00:00:07 +02:00
executor: add executor::exit (#1155)
This allows blocking on executors from within a `threadpool::blocking` call.
This commit is contained in:
committed by
Carl Lerche
parent
5dcb379f6d
commit
cad0c35623
@@ -1,6 +1,7 @@
|
||||
use worker::Worker;
|
||||
|
||||
use futures::Poll;
|
||||
use tokio_executor;
|
||||
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
@@ -142,8 +143,11 @@ where
|
||||
// If the transition cannot happen, exit early
|
||||
try_ready!(res);
|
||||
|
||||
// Currently in blocking mode, so call the inner closure
|
||||
let ret = f();
|
||||
// Currently in blocking mode, so call the inner closure.
|
||||
//
|
||||
// "Exit" the current executor in case the blocking function wants
|
||||
// to call a different executor.
|
||||
let ret = tokio_executor::exit(move || f());
|
||||
|
||||
// Try to transition out of blocking mode. This is a fast path that takes
|
||||
// back ownership of the worker if the worker handoff didn't complete yet.
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#![doc(html_root_url = "https://docs.rs/tokio-threadpool/0.1.14")]
|
||||
#![deny(warnings, missing_docs, missing_debug_implementations)]
|
||||
// Our MSRV doesn't allow us to fix these warnings yet
|
||||
#![allow(rust_2018_idioms)]
|
||||
|
||||
//! A work-stealing based thread pool for executing futures.
|
||||
//!
|
||||
|
||||
Reference in New Issue
Block a user