Struct killswitch::KillSwitch
source · pub struct KillSwitch(/* private fields */);
Expand description
The KillSwitch is used both to signal termination and waiting for termination.
Implementations§
source§impl KillSwitch
impl KillSwitch
sourcepub fn trigger(&self)
pub fn trigger(&self)
Mark killswitch as triggered and signal all waiting tasks that they should terminate.
sourcepub fn wait(&self) -> WaitFuture ⓘ
pub fn wait(&self) -> WaitFuture ⓘ
Wait for the killswitch to be triggered.
sourcepub fn finalize(&self) -> FinalizedFuture ⓘ
pub fn finalize(&self) -> FinalizedFuture ⓘ
Return a Future that will return Ready
once there are no more waiters
waiting on this killswitch to be triggered.
The KillSwitch must be triggered before calling this function, or the returned future will return an error.
sourcepub fn reset(&self)
pub fn reset(&self)
Reset KillSwitch
.
Care should be taken when using this. Generally speaking it should only
be used immediately following a KillSwitch::finalize()
:
use killswitch::KillSwitch;
let ks = KillSwitch::default();
assert_eq!(ks.is_triggered(), false);
// Trigger kill switch
ks.trigger();
assert_eq!(ks.is_triggered(), true);
ks.finalize().await;
ks.reset();
// KillSwitch became untriggered again
assert_eq!(ks.is_triggered(), false);
Applications should prefer to call KillSwitch::finalize_reset()
rather than calling finalize()
and reset()
.
sourcepub async fn finalize_reset(&self) -> Result<(), ()>
pub async fn finalize_reset(&self) -> Result<(), ()>
Finalize and reset KillSwitch
.
Returns Err(())
if the KillSwitch
wasn’t in triggered state.
sourcepub fn is_triggered(&self) -> bool
pub fn is_triggered(&self) -> bool
Return a boolean indicating whether kill switch has been triggered.
Returns true
if kill switch has been triggered. Returns false
otherwise.
Trait Implementations§
source§impl Clone for KillSwitch
impl Clone for KillSwitch
source§fn clone(&self) -> KillSwitch
fn clone(&self) -> KillSwitch
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more