Struct interruptible::InterruptibilityState
source · 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>
impl<'rx> InterruptibilityState<'rx, 'static>
sourcepub fn new(interruptibility: Interruptibility<'rx>) -> Self
pub fn new(interruptibility: Interruptibility<'rx>) -> Self
Returns a new InterruptibilityState
.
sourcepub fn new_non_interruptible() -> Self
pub fn new_non_interruptible() -> Self
Returns a new InterruptibilityState
with
Interruptibility::NonInterruptible
support.
sourcepub fn new_ignore_interruptions(
interrupt_rx: OwnedOrMutRef<'rx, Receiver<InterruptSignal>>
) -> Self
pub fn new_ignore_interruptions( interrupt_rx: OwnedOrMutRef<'rx, Receiver<InterruptSignal>> ) -> Self
Returns a new InterruptibilityState
with
InterruptStrategy::IgnoreInterruptions
.
sourcepub fn new_finish_current(
interrupt_rx: OwnedOrMutRef<'rx, Receiver<InterruptSignal>>
) -> Self
pub fn new_finish_current( interrupt_rx: OwnedOrMutRef<'rx, Receiver<InterruptSignal>> ) -> Self
Returns a new InterruptibilityState
with
InterruptStrategy::FinishCurrent
.
sourcepub fn new_poll_next_n(
interrupt_rx: OwnedOrMutRef<'rx, Receiver<InterruptSignal>>,
n: u64
) -> Self
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>
impl<'rx, 'intx> InterruptibilityState<'rx, 'intx>
sourcepub fn set_fn_interrupt_activate<F>(&mut self, fn_interrupt_activate: Option<F>)where
F: Fn() + 'intx,
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 n
th poll, rather than when the
InterruptSignal
is received.
The function will only run once; subsequent polls will not run the function again.
sourcepub fn set_fn_interrupt_poll_item<F>(
&mut self,
fn_interrupt_poll_item: Option<F>
)where
F: Fn() + 'intx,
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 n
th 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.
sourcepub 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,
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.
sourcepub fn is_interrupted(&self) -> bool
pub fn is_interrupted(&self) -> bool
Returns if this InterruptibilityState
is considered interrupted based
on the chosen strategy.
- For
IgnoreInterruptions
, this always returnsfalse
. - For
FinishCurrent
, this returnstrue
after receiving at least oneInterruptSignal
. - For
PollNextN
, this returnstrue
if the stream has been polled at leastn
times since receiving theInterruptSignal
.
sourcepub fn item_interrupt_poll(
&mut self,
increment_item_count: bool
) -> Option<InterruptSignal>
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 totrue
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
.
sourcepub fn interruptibility(&self) -> &Interruptibility<'rx>
pub fn interruptibility(&self) -> &Interruptibility<'rx>
Returns the interruptibility support of the application.
sourcepub fn interruptibility_mut(&mut self) -> &mut Interruptibility<'rx>
pub fn interruptibility_mut(&mut self) -> &mut Interruptibility<'rx>
Returns a mutable reference to the interruptibility support of the application.
sourcepub fn poll_since_interrupt_count(&self) -> u64
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.
sourcepub fn fn_interrupt_poll_item(&self) -> Option<&Box<dyn Fn() + 'intx>>
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.
sourcepub fn interrupt_strategy(&self) -> Option<InterruptStrategy>
pub fn interrupt_strategy(&self) -> Option<InterruptStrategy>
Returns the InterruptStrategy
if present.
Trait Implementations§
source§impl<'rx, 'intx> Debug for InterruptibilityState<'rx, 'intx>
impl<'rx, 'intx> Debug for InterruptibilityState<'rx, 'intx>
source§impl<'rx> From<Interruptibility<'rx>> for InterruptibilityState<'rx, 'static>
impl<'rx> From<Interruptibility<'rx>> for InterruptibilityState<'rx, 'static>
source§fn from(interruptibility: Interruptibility<'rx>) -> Self
fn from(interruptibility: Interruptibility<'rx>) -> Self
Returns a new InterruptibilityState
.