diff --git a/tokio/src/runtime/blocking/pool.rs b/tokio/src/runtime/blocking/pool.rs index d681ed28458..1f209b6b794 100644 --- a/tokio/src/runtime/blocking/pool.rs +++ b/tokio/src/runtime/blocking/pool.rs @@ -317,6 +317,8 @@ impl Spawner { R: Send + 'static, { let fut = BlockingTask::new(func); + #[cfg(feature = "test-util")] + let fut = crate::time::inhibit_auto_advance(fut); let id = task::Id::next(); #[cfg(all(tokio_unstable, feature = "tracing"))] let fut = { @@ -337,9 +339,6 @@ impl Spawner { #[cfg(not(all(tokio_unstable, feature = "tracing")))] let _ = name; - #[cfg(feature = "test-util")] - let fut = crate::time::inhibit_auto_advance(fut); - let (task, handle) = task::unowned(fut, NoopSchedule, id); let spawned = self.spawn_task(Task::new(task, is_mandatory), rt); diff --git a/tokio/src/time/clock.rs b/tokio/src/time/clock.rs index 55e6b3eea9d..f321fd6f4f9 100644 --- a/tokio/src/time/clock.rs +++ b/tokio/src/time/clock.rs @@ -141,7 +141,10 @@ cfg_test_util! { /// it returns `Ready` or is dropped. /// /// This is a no-op when called from outside the Tokio runtime. - pub(crate) fn inhibit_auto_advance(fut: F) -> impl Future { + pub(crate) fn inhibit_auto_advance(fut: F) -> impl Future + Send + 'static + where + F: Future + Send + 'static, + { // Bump the inhibit count immediately, not inside the async block, to // avoid a race condition when used by spawn_blocking. let guard = clock().map(|clock| {