pub struct BlockingPermit<'a> { /* private fields */ }
Expand description
A scoped permit for blocking operations. When dropped (out of scope or manually), the permit is released.
Implementations§
Source§impl<'a> BlockingPermit<'a>
impl<'a> BlockingPermit<'a>
Sourcepub fn enter(&self)
pub fn enter(&self)
Enter the blocking section of code on the current thread.
This is a secondary step from completion of the
BlockingPermitFuture
as it must be called on the same thread,
immediately before the blocking section. The blocking permit should
then be dropped at the end of the blocking section. If the
tokio-threaded feature is or might be used, run
should be
used instead.
§Panics
Panics if this BlockingPermit
has already been entered.
Sourcepub fn run<F, T>(self, f: F) -> Twhere
F: FnOnce() -> T,
pub fn run<F, T>(self, f: F) -> Twhere
F: FnOnce() -> T,
Enter and run the blocking closure.
When the tokio-threaded feature is enabled, this wraps the
tokio::task::block_in_place
call, as a secondary step from completion
of the BlockingPermitFuture
that must be called on the same
thread.
In any case, the permit is passed by value and will be dropped on termination of this call.
§Panics
Panics if this BlockingPermit
has already been entered.