Struct permit::Permit [−][src]
pub struct Permit { /* fields omitted */ }
A struct for cancelling operations.
Use new_sub()
to make a subordinate permit.
Call revoke()
to revoke a permit
and its subordinate permits, recursively.
Example
Graceful shutdown:
let top_permit = permit::Permit::new(); // Start some worker threads. for _ in 0..5 { let permit = top_permit.new_sub(); std::thread::spawn(move || { while !permit.is_revoked() { // ... } }); } wait_for_shutdown_signal(); // Revoke all thread permits and wait for them to // finish and drop their permits. top_permit.revoke().try_wait_for( core::time::Duration::from_secs(3));
Implementations
impl Permit
[src]
impl Permit
[src]#[must_use]pub fn new() -> Self
[src]
Makes a new permit.
This permit is not subordinate to any other permit. It has no superior.
Dropping the permit revokes it and any subordinate permits.
#[must_use]pub fn new_sub(&self) -> Self
[src]
Make a new permit that is subordinate to this permit.
Call revoke()
to revoke a permit
and its subordinate permits, recursively.
Dropping the permit revokes it and any subordinate permits.
#[must_use]pub fn is_revoked(&self) -> bool
[src]
Returns true
if revoke()
has previously been called
on this permit or any of its superiors.
#[must_use]pub fn ok(&self) -> Option<()>
[src]
Returns Some(())
if revoke()
has not been called
on this permit or any of its superiors.
pub fn revoke(&self) -> &Self
[src]
Revokes this permit and all subordinate permits.
#[must_use]pub fn has_subs(&self) -> bool
[src]
Returns true
if this permit has any subordinate permits that have not
been dropped.
This includes direct subordinates and their subordinates, recursively.
pub fn wait(&self)
[src]
Wait indefinitely for all subordinate permits to drop.
This waits for all direct subordinates and their subordinates, recursively.
pub fn try_wait_for(&self, duration: Duration) -> Result<(), DeadlineExceeded>
[src]
Wait for all subordinate permits to drop.
This waits for all direct subordinates and their subordinates, recursively.
Errors
Returns DeadlineExceeded
if the subordinate permits
are not all dropped before duration
passes.
pub fn try_wait_until(&self, deadline: Instant) -> Result<(), DeadlineExceeded>
[src]
Wait for all subordinate permits to drop.
This waits for all direct subordinates and their subordinates, recursively.
Errors
Returns DeadlineExceeded
if the subordinate permits
are not all dropped before deadline
passes.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Permit
impl RefUnwindSafe for Permit
impl UnwindSafe for Permit
impl UnwindSafe for Permit
Blanket Implementations
impl<F> IntoFuture for F where
F: Future,
[src]
impl<F> IntoFuture for F where
F: Future,
[src]type Output = <F as Future>::Output
into_future
)The output that the future will produce on completion.
type Future = F
into_future
)Which kind of future are we turning this into?