current-thread: fix shutdown on idle (#763)

When spawning using `Handle` while on the executor, tasks were being
double counted. This prevented the number of active tasks to reach zero,
thus preventing the executor from shutting down.

This changes `spawn` to check if being called from the executor
**before** incrementing the number of active tasks.

Fixes #760
This commit is contained in:
Carl Lerche
2018-11-20 09:17:07 -08:00
committed by GitHub
parent 9b1a45cc6a
commit ed3ece266b
2 changed files with 26 additions and 7 deletions
@@ -778,6 +778,25 @@ fn spawn_from_other_thread_unpark() {
).unwrap();
}
#[test]
fn spawn_from_executor_with_handle() {
let mut current_thread = CurrentThread::new();
let handle = current_thread.handle();
let (tx, rx) = oneshot::channel();
current_thread.spawn(lazy(move || {
handle.spawn(lazy(move || {
tx.send(()).unwrap();
Ok(())
})).unwrap();
Ok::<_, ()>(())
}));
current_thread.run();
rx.wait().unwrap();
}
fn ok() -> future::FutureResult<(), ()> {
future::ok(())
}