Struct permit::Permit [−][src]
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 an drop their permits. top_permit.revoke().try_wait_for( core::time::Duration::from_secs(3));
Implementations
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
impl Clone for Permit
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Default for Permit
[src]
impl Drop for Permit
[src]
impl Future for Permit
[src]
Auto Trait Implementations
impl RefUnwindSafe for Permit
impl Send for Permit
impl Sync for Permit
impl Unpin for Permit
impl UnwindSafe for Permit
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<F> IntoFuture for F where
F: Future,
[src]
F: Future,
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?
pub fn into_future(self) -> <F as IntoFuture>::Future
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,