mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-24 00:00:11 +02:00
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:
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user