Set the current_thread context for the run future.
This allows spawning new futures using `current_thread::spawn`.
diff --git a/src/reactor/mod.rs b/src/reactor/mod.rs
index 31cdee7..ec75181 100644
--- a/src/reactor/mod.rs
+++ b/src/reactor/mod.rs
@@ -242,10 +242,16 @@
let mut enter = tokio_executor::enter()
.ok().expect("cannot recursively call into `Core`");
+ let notify = &self.notify_future;
+ let mut current_thread = self.executor.borrow_mut();
+
let res = try!(CURRENT_LOOP.set(self, || {
::tokio_reactor::with_default(&handle1, &mut enter, |enter| {
- tokio_executor::with_default(&mut executor1, enter, |_| {
- task.poll_future_notify(&self.notify_future, 0)
+ tokio_executor::with_default(&mut executor1, enter, |enter| {
+ current_thread.enter(enter)
+ .block_on(future::lazy(|| {
+ Ok::<_, ()>(task.poll_future_notify(notify, 0))
+ })).unwrap()
})
})
}));
diff --git a/tests/spawn.rs b/tests/spawn.rs
index d1cdb48..aafae85 100644
--- a/tests/spawn.rs
+++ b/tests/spawn.rs
@@ -56,6 +56,27 @@
}
#[test]
+fn simple_send_current_thread() {
+ drop(env_logger::init());
+ let mut lp = Core::new().unwrap();
+
+ let (tx, rx) = oneshot::channel();
+
+ lp.run(future::lazy(move || {
+ tokio::executor::current_thread::spawn(future::lazy(move || {
+ tx.send(1).unwrap();
+ Ok(())
+ }));
+
+ rx.map_err(|_| panic!())
+ .and_then(|v| {
+ assert_eq!(v, 1);
+ Ok(())
+ })
+ })).unwrap();
+}
+
+#[test]
fn tokio_spawn_from_fut() {
drop(env_logger::init());
let mut lp = Core::new().unwrap();