diff --git a/tokio/src/runtime/context.rs b/tokio/src/runtime/context.rs index c816959c17d..afa8c3f2e4f 100644 --- a/tokio/src/runtime/context.rs +++ b/tokio/src/runtime/context.rs @@ -24,22 +24,6 @@ pub(crate) fn current() -> Handle { } } -cfg_time! { - cfg_test_util! { - pub(crate) fn clock() -> Option { - match CONTEXT.try_with(|ctx| { - let ctx = ctx.borrow(); - ctx - .as_ref() - .map(|ctx| ctx.inner.clock().clone()) - }) { - Ok(clock) => clock, - Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR), - } - } - } -} - /// Sets this [`Handle`] as the current active [`Handle`]. /// /// [`Handle`]: Handle diff --git a/tokio/src/time/clock.rs b/tokio/src/time/clock.rs index c3b180eb5c6..01ab50d38a9 100644 --- a/tokio/src/time/clock.rs +++ b/tokio/src/time/clock.rs @@ -33,7 +33,13 @@ cfg_test_util! { cfg_rt! { fn clock() -> Option { - crate::runtime::context::clock() + use crate::runtime::Handle; + + match Handle::try_current() { + Ok(handle) => Some(handle.inner.clock().clone()), + Err(ref e) if e.is_missing_context() => None, + Err(_) => panic!("{}", crate::util::error::THREAD_LOCAL_DESTROYED_ERROR), + } } }