mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-09-25 12:00:35 +00:00
runtime: do not defer yield_now
inside block_in_place
(#6999)
This commit is contained in:
parent
bce9780dd3
commit
f8948ea021
@ -183,7 +183,14 @@ cfg_rt! {
|
|||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub(super) fn with_scheduler<R>(f: impl FnOnce(Option<&scheduler::Context>) -> R) -> R {
|
pub(super) fn with_scheduler<R>(f: impl FnOnce(Option<&scheduler::Context>) -> R) -> R {
|
||||||
let mut f = Some(f);
|
let mut f = Some(f);
|
||||||
CONTEXT.try_with(|c| c.scheduler.with(f.take().unwrap()))
|
CONTEXT.try_with(|c| {
|
||||||
|
let f = f.take().unwrap();
|
||||||
|
if matches!(c.runtime.get(), EnterRuntime::Entered { .. }) {
|
||||||
|
c.scheduler.with(f)
|
||||||
|
} else {
|
||||||
|
f(None)
|
||||||
|
}
|
||||||
|
})
|
||||||
.unwrap_or_else(|_| (f.take().unwrap())(None))
|
.unwrap_or_else(|_| (f.take().unwrap())(None))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#![allow(unknown_lints, unexpected_cfgs)]
|
#![allow(unknown_lints, unexpected_cfgs)]
|
||||||
#![cfg(all(feature = "full", tokio_unstable))]
|
#![cfg(all(feature = "full", not(target_os = "wasi"), tokio_unstable))]
|
||||||
|
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
use tokio_test::task::spawn;
|
use tokio_test::task::spawn;
|
||||||
@ -15,3 +15,11 @@ fn yield_now_outside_of_runtime() {
|
|||||||
assert!(task.is_woken());
|
assert!(task.is_woken());
|
||||||
assert!(task.poll().is_ready());
|
assert!(task.poll().is_ready());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread")]
|
||||||
|
async fn yield_now_external_executor_and_block_in_place() {
|
||||||
|
let j = tokio::spawn(async {
|
||||||
|
task::block_in_place(|| futures::executor::block_on(task::yield_now()));
|
||||||
|
});
|
||||||
|
j.await.unwrap();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user