pub(crate) fn try_enter_blocking_region() -> Option<BlockingRegionGuard> {
CONTEXT
.try_with(|c| { if c.runtime.get().is_entered() {
None
} else {
Some(BlockingRegionGuard::new())
} // If accessing the thread-local fails, the thread is terminating // and thread-locals are being destroyed. Because we don't know if // we are currently in a runtime or not, we default to being // permissive.
})
.unwrap_or_else(|_| Some(BlockingRegionGuard::new()))
}
/// Disallows blocking in the current runtime context until the guard is dropped. pub(crate) fn disallow_block_in_place() -> DisallowBlockInPlaceGuard { let reset = CONTEXT.with(|c| { iflet EnterRuntime::Entered {
allow_block_in_place: true,
} = c.runtime.get()
{
c.runtime.set(EnterRuntime::Entered {
allow_block_in_place: false,
}); true
} else { false
}
});
/// Blocks the thread on the specified future, returning the value with /// which that future completes. pub(crate) fn block_on<F>(&mutself, f: F) -> Result<F::Output, AccessError> where
F: std::future::Future,
{ usecrate::runtime::park::CachedParkThread;
letmut park = CachedParkThread::new();
park.block_on(f)
}
/// Blocks the thread on the specified future for **at most** `timeout` /// /// If the future completes before `timeout`, the result is returned. If /// `timeout` elapses, then `Err` is returned. pub(crate) fn block_on_timeout<F>(&mutself, f: F, timeout: Duration) -> Result<F::Output, ()> where
F: std::future::Future,
{ usecrate::runtime::park::CachedParkThread; use std::task::Context; use std::task::Poll::Ready; use std::time::Instant;
letmut park = CachedParkThread::new(); let waker = park.waker().map_err(|_| ())?; letmut cx = Context::from_waker(&waker);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.