diff --git a/tokio/src/task/yield_now.rs b/tokio/src/task/yield_now.rs index a58e85ee7..ea09804ad 100644 --- a/tokio/src/task/yield_now.rs +++ b/tokio/src/task/yield_now.rs @@ -46,6 +46,12 @@ pub async fn yield_now() { yielded = true; + // Don't wake the task immediately, as that would push it right back + // onto the run queue and it could be polled again before other tasks + // or the IO/timer driver get a chance to run. Instead, hand the waker + // to the scheduler, which wakes deferred tasks only after it has run + // out of ready tasks and polled the driver. When polled from outside + // a Tokio runtime, the waker is woken immediately. context::defer(cx.waker()); Poll::Pending