pub struct CancelToken { /* private fields */ }Expand description
A latch a caller flips to stop in-flight gateway work.
04-subsystem-contracts.md requires the gateway to support cancellation, and
the requirement has teeth precisely because of pagination: an organization
inventory is a sequence of requests, and a refresh the operator has already
navigated away from should not keep spending the shared budget on pages
nobody will read.
So cancellation is checked in two places, and both matter. Before each request — which is what stops a multi-page walk between pages — and concurrently with the request in flight, which is what stops a walk that is blocked on a socket.
Cloning shares the latch. Cancelling is one-way: a token that has been cancelled stays cancelled, because “cancel, then reuse” is how a caller ends up with a token whose state depends on a race.
Implementations§
Source§impl CancelToken
impl CancelToken
pub fn is_cancelled(&self) -> bool
Sourcepub fn check(&self) -> Result<(), InventoryError>
pub fn check(&self) -> Result<(), InventoryError>
Err(InventoryError::Cancelled) once cancelled, so a call site can
bail with ?.
§Errors
Sourcepub async fn run<T>(
&self,
work: impl Future<Output = Result<T, InventoryError>>,
) -> Result<T, InventoryError>
pub async fn run<T>( &self, work: impl Future<Output = Result<T, InventoryError>>, ) -> Result<T, InventoryError>
Run work, abandoning it if this token is cancelled first.
§Errors
InventoryError::Cancelled, or whatever work fails with.
Trait Implementations§
Source§impl Clone for CancelToken
impl Clone for CancelToken
Source§fn clone(&self) -> CancelToken
fn clone(&self) -> CancelToken
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more