pub struct SoftCycleController<T: Payload = ()> { /* private fields */ }Expand description
Coordination controller for soft restarts and graceful shutdowns.
SoftCycleController exposes a tiny async-friendly coordination protocol:
- producers call
try_notifyto publish a notification with a payload and notify waiters; - producers call
try_clearto move back to the non-notified state; - consumers create a
SoftCycleListenervialistenerto wait for notifications with payloads.
See the crate-level documentation for detailed documentation and usage examples.
Implementations§
Source§impl<T: Payload> SoftCycleController<T>
impl<T: Payload> SoftCycleController<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new SoftCycleController.
Sourcepub fn try_notify(&self, payload: T) -> Result<u32, T>
pub fn try_notify(&self, payload: T) -> Result<u32, T>
Attempts to notify. On success returns Ok(sequence_number) where the sequence number
starts from 0 and increases. On failure (already notified) returns
Err(payload) with the payload unchanged. Never blocks.
Sourcepub fn try_clear(&self) -> Result<u32, ()>
pub fn try_clear(&self) -> Result<u32, ()>
Clears the notified state. On success returns Ok(sequence_number) for the notification
sequence number that was cleared. On failure (not currently notified) returns Err(()).
Never blocks.
Clearing after a notify does not prevent listeners already waiting from receiving the notification.
Sourcepub fn listener<'a>(&'a self) -> SoftCycleListener<'a, T> ⓘ
pub fn listener<'a>(&'a self) -> SoftCycleListener<'a, T> ⓘ
Returns a listener that resolves when a notification is observed, with Ok(payload).
If already notified, it may complete in a finite number of polls; if not yet
notified, it completes in a finite number of polls after the next try_notify.
After multiple notify/clear cycles, the listener returns one of the payloads (no
guarantee of earliest or latest). See the crate-level documentation.