Skip to main content

Module cancel

Module cancel 

Source
Expand description

Reference-counted cancel tokens and the future combinator that makes cancellation of an async call observable.

A consumer creates a token with {prefix}_cancel_token_create and passes it to a cancellable async launcher. The launcher takes its own reference (a CancelToken), so the consumer may cancel and destroy its reference at any time afterwards, even before the call completes. Cancelling wakes every future registered on the token; the launcher’s Cancellable wrapper then drops the producer’s future and the call completes with CANCELLED_ERROR_CODE.

Each in-flight call registers once, when it’s first polled, and keeps its current waker in an AtomicWaker of its own, so a poll refreshes the waker without taking a lock.

Structs§

AtomicWaker
A waker slot that one task registers into and any thread wakes, without a lock (the algorithm of futures’ AtomicWaker).
CancelToken
The producer’s handle on a consumer’s cancel token, accepted as the final parameter of a #[weaveffi::cancellable] async fn.
Cancellable
A future that resolves to Some(output) when inner completes, or to None as soon as the token is cancelled, dropping inner first.
FfiCancelToken
The shared state behind a cancel token ({prefix}_cancel_token in C, an opaque type).

Functions§

cancel_token_cancel⚠
The body of {prefix}_cancel_token_cancel: request cancellation and wake every future waiting on the token. Idempotent; a null token is a no-op.
cancel_token_create
The body of {prefix}_cancel_token_create: a fresh, uncancelled token holding one reference, which the consumer releases with cancel_token_destroy.
cancel_token_destroy⚠
The body of {prefix}_cancel_token_destroy: release the consumer’s reference. In-flight calls keep their own references, so this is safe to call while a call that received the token is still running. A null token is a no-op.
cancel_token_is_cancelled⚠
The body of {prefix}_cancel_token_is_cancelled. A null token reads as never cancelled.