executor, threadpool: forward port fix from #1155 (#1433)

Add executor::exit, allowing other executors inside threadpool::blocking.
This commit is contained in:
Ilya Lakhin
2019-08-13 21:12:49 -07:00
committed by Carl Lerche
parent 517162792f
commit fb9809c068
4 changed files with 62 additions and 2 deletions
+5 -1
View File
@@ -4,6 +4,7 @@ use futures_core::ready;
use std::error::Error;
use std::fmt;
use std::task::Poll;
use tokio_executor;
/// Error raised by `blocking`.
pub struct BlockingError {
@@ -140,7 +141,10 @@ where
ready!(res)?;
// Currently in blocking mode, so call the inner closure
let ret = f();
//
// "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.