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§
- Atomic
Waker - A waker slot that one task registers into and any thread wakes, without a
lock (the algorithm of
futures’AtomicWaker). - Cancel
Token - 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)wheninnercompletes, or toNoneas soon as the token is cancelled, droppinginnerfirst. - FfiCancel
Token - The shared state behind a cancel token (
{prefix}_cancel_tokenin 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 withcancel_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.