pub struct InterruptibilityState<'rx, 'intx> { /* private fields */ }
Expand description

Whether interruptibility is supported, and number of times interrupt signals have been received.

Implementations§

source§

impl<'rx> InterruptibilityState<'rx, 'static>

source

pub fn new(interruptibility: Interruptibility<'rx>) -> Self

Returns a new InterruptibilityState.

source

pub fn new_non_interruptible() -> Self

Returns a new InterruptibilityState with Interruptibility::NonInterruptible support.

source

pub fn new_ignore_interruptions( interrupt_rx: OwnedOrMutRef<'rx, Receiver<InterruptSignal>> ) -> Self

Returns a new InterruptibilityState with InterruptStrategy::IgnoreInterruptions.

source

pub fn new_finish_current( interrupt_rx: OwnedOrMutRef<'rx, Receiver<InterruptSignal>> ) -> Self

Returns a new InterruptibilityState with InterruptStrategy::FinishCurrent.

source

pub fn new_poll_next_n( interrupt_rx: OwnedOrMutRef<'rx, Receiver<InterruptSignal>>, n: u64 ) -> Self

Returns a new InterruptibilityState with InterruptStrategy::PollNextN.

source§

impl<'rx, 'intx> InterruptibilityState<'rx, 'intx>

source

pub fn set_fn_interrupt_activate<F>(&mut self, fn_interrupt_activate: Option<F>)
where F: Fn() + 'intx,

Sets the function to run when an interruption is activated.

For PollNextN, this will run on the nth poll, rather than when the InterruptSignal is received.

The function will only run once; subsequent polls will not run the function again.

source

pub fn set_fn_interrupt_poll_item<F>( &mut self, fn_interrupt_poll_item: Option<F> )
where F: Fn() + 'intx,

Sets the function to run the first time the underlying stream is polled after an interruption is activated.

For PollNextN, this will run on the nth poll, rather than when the InterruptSignal is received.

The function will only run once; subsequent polls will not run the function again.

Notes

This differs from fn_interrupt_activate in that fn_interrupt_activate is run when the interruption is activated, and any poll occurs that may be advancing a previously polled item. i.e. self.stream.poll() may still return Poll::Pending, so PollOutcome::Interrupted is not yet surfaced to the consumer of the InterruptibleStream.

Whereas fn_interrupt_poll_item is run when the poll actually polls a new item from the underlying stream.

source

pub fn reborrow<'rx_local, 'intx_local>( &'rx_local mut self ) -> InterruptibilityState<'rx_local, 'intx_local>
where 'rx: 'rx_local + 'intx_local, 'intx: 'rx_local + 'intx_local, 'rx_local: 'intx_local,

Reborrows this InterruptibilityState with a shorter lifetime.

source

pub fn is_interrupted(&self) -> bool

Returns if this InterruptibilityState is considered interrupted based on the chosen strategy.

  • For IgnoreInterruptions, this always returns false.
  • For FinishCurrent, this returns true after receiving at least one InterruptSignal.
  • For PollNextN, this returns true if the stream has been polled at least n times since receiving the InterruptSignal.
source

pub fn item_interrupt_poll( &mut self, increment_item_count: bool ) -> Option<InterruptSignal>

Tests if an item should be interrupted.

If an interrupt signal has not been received, this returns None.

When an interrupt signal has been received, this may still return None if the interrupt strategy allows for additional items to be completed before the process should be stopped.

Parameters
  • increment_item_count: Set this to true if this poll is for a new item, false if polling for interruptions while an item is being streamed.

Note: It is important that this is called once per Stream::Item or Future, as the invocation of this method is used to track state for strategies like PollNextN.

source

pub fn interruptibility(&self) -> &Interruptibility<'rx>

Returns the interruptibility support of the application.

source

pub fn interruptibility_mut(&mut self) -> &mut Interruptibility<'rx>

Returns a mutable reference to the interruptibility support of the application.

source

pub fn poll_since_interrupt_count(&self) -> u64

Returns the number of times item_interrupt_poll is called since the very first interrupt signal was received.

If the interruption signal has not been received, this returns 0.

source

pub fn fn_interrupt_poll_item(&self) -> Option<&Box<dyn Fn() + 'intx>>

Returns the function to run the first time the underlying stream is polled after an interruption is activated.

source

pub fn interrupt_strategy(&self) -> Option<InterruptStrategy>

Returns the InterruptStrategy if present.

Trait Implementations§

source§

impl<'rx, 'intx> Debug for InterruptibilityState<'rx, 'intx>

source§

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

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

impl<'rx> From<Interruptibility<'rx>> for InterruptibilityState<'rx, 'static>

source§

fn from(interruptibility: Interruptibility<'rx>) -> Self

Returns a new InterruptibilityState.

Auto Trait Implementations§

§

impl<'rx, 'intx> !RefUnwindSafe for InterruptibilityState<'rx, 'intx>

§

impl<'rx, 'intx> !Send for InterruptibilityState<'rx, 'intx>

§

impl<'rx, 'intx> !Sync for InterruptibilityState<'rx, 'intx>

§

impl<'rx, 'intx> Unpin for InterruptibilityState<'rx, 'intx>

§

impl<'rx, 'intx> !UnwindSafe for InterruptibilityState<'rx, 'intx>

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<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.