executor: add executor::exit (#1155)

This allows blocking on executors from within a `threadpool::blocking` call.
This commit is contained in:
Sean McArthur
2019-06-24 09:22:54 -07:00
committed by Carl Lerche
parent 5dcb379f6d
commit cad0c35623
6 changed files with 71 additions and 4 deletions
+23
View File
@@ -1,3 +1,4 @@
extern crate tokio_executor;
extern crate tokio_threadpool;
extern crate env_logger;
@@ -44,6 +45,28 @@ fn basic() {
rx2.recv().unwrap();
}
#[test]
fn other_executors_can_run_inside_blocking() {
let _ = ::env_logger::try_init();
let pool = Builder::new().pool_size(1).max_blocking(1).build();
let (tx, rx) = mpsc::channel();
pool.spawn(lazy(move || {
let res = blocking(|| {
let _e = tokio_executor::enter().expect("nested blocking enter");
tx.send(()).unwrap();
})
.unwrap();
assert!(res.is_ready());
Ok(().into())
}));
rx.recv().unwrap();
}
#[test]
fn notify_task_on_capacity() {
const BLOCKING: usize = 10;