Skip to content

Commit

Permalink
task: wake LocalSet on spawn_local (#3369)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron committed Jan 9, 2021
1 parent 2fe2f04 commit 22c27b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions tokio/src/task/local.rs
Expand Up @@ -283,6 +283,7 @@ impl LocalSet {
let future = crate::util::trace::task(future, "local");
let (task, handle) = unsafe { task::joinable_local(future) };
self.context.tasks.borrow_mut().queue.push_back(task);
self.context.shared.waker.wake();
handle
}

Expand Down
14 changes: 14 additions & 0 deletions tokio/tests/task_local_set.rs
@@ -1,6 +1,11 @@
#![warn(rust_2018_idioms)]
#![cfg(feature = "full")]

use futures::{
future::{pending, ready},
FutureExt,
};

use tokio::runtime::{self, Runtime};
use tokio::sync::{mpsc, oneshot};
use tokio::task::{self, LocalSet};
Expand Down Expand Up @@ -486,6 +491,15 @@ async fn acquire_mutex_in_drop() {
drop(local);
}

#[tokio::test]
async fn spawn_wakes_localset() {
let local = LocalSet::new();
futures::select! {
_ = local.run_until(pending::<()>()).fuse() => unreachable!(),
ret = async { local.spawn_local(ready(())).await.unwrap()}.fuse() => ret
}
}

fn rt() -> Runtime {
tokio::runtime::Builder::new_current_thread()
.enable_all()
Expand Down

0 comments on commit 22c27b9

Please sign in to comment.