Skip to main content

WaitTokenGuard

Struct WaitTokenGuard 

Source
pub struct WaitTokenGuard { /* private fields */ }

Implementations§

Source§

impl WaitTokenGuard

Source

pub fn new() -> Self

Source

pub fn clone_tk(&self) -> WaitToken

Methods from Deref<Target = WaitToken>§

Source

pub fn spawn_terminator(&self) -> JoinHandle<Result<(), Error>>

Spawns background fetch to listem SIGTERM & SIGINT events and calls cancel

Source

pub fn cancel(&self) -> CancelState

Set state to ‘cancelled’. Futures waiting for token will complete and streams terminated.

Source

pub fn reset(&self)

Set state to ‘not cancelled’

Source

pub fn is_cancelled(&self) -> bool

Source

pub fn cancelled(&self) -> WaitTokenCancelled

Source

pub fn until_cancel(&self) -> TakeUntil<Repeat<()>, WaitTokenCancelled>

Make a stream that will emit items until token is cancelled

Source

pub fn on_cancel(&self) -> Once<WaitTokenCancelled>

Source

pub fn repeat_until_cancel(&self, frq: Duration) -> WaitTokenRepeat<Self>

Make an object that will wait for delay every iteration and return false if token is cancelled. Common usage is with while loop.

Example:

let mut repeater = cancellation.repeat_until_cancel(Duration::from_secs(1));
while repeater.next().await {
    do_something();
}
Source

pub async fn run_fn<Fut: Future>(&self, fut: Fut) -> Option<Fut::Output>

Run future. Future will be aborted when token is cancelled

Source

pub fn make_child_token(&self) -> Self

Create a sub-token that will cancel if current token cancelled.
Cancel on child token will not cancel parent

Source

pub fn guard(&self) -> WaitTokenGuard

Create a guard that will cancel wait token on drop

Trait Implementations§

Source§

impl Debug for WaitTokenGuard

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WaitTokenGuard

Source§

fn default() -> WaitTokenGuard

Returns the “default value” for a type. Read more
Source§

impl Deref for WaitTokenGuard

Source§

type Target = WaitToken

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Drop for WaitTokenGuard

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.