eve.core.cancellation

EVE Cancellation Support

This module provides a @nogc cancellation mechanism based on explicit cancellation tokens and sources. It allows asynchronous operations to be cancelled mid-flight while ensuring that all resources are cleaned up correctly.

Types 5

enumCancelReason : ubyte

Reason an operation was terminated.

SUCCESSOperation completed normally.
CANCELLEDOperation was cancelled via a CancelToken.
TIMEOUTOperation timed out.
CLOSEDUnderlying resource was closed.
ERRORSystem error.

Shared state for cancellation tracking.

This struct is intended to be used with CancelSource and CancelToken.

Fields
ubyte cancelledAtomic flag for cancellation (0 = false, 1 = true).

Cancellation token — an opaque, @nogc handle passed to async operations.

When the corresponding source is cancelled, the token's isCancelled property will return true.

Fields
private shared(CancelState) * _state
invalidSentinel invalid token.
Methods
bool isCancelled() @property const @safe nothrow @nogcCheck if cancellation has been requested.
bool isValid() @property const pure nothrow @nogc @safeCheck if this token is valid.

The owner of a cancellation state.

A source can be used to trigger cancellation and provide tokens to multiple asynchronous operations.

Fields
private CancelState _state
Methods
CancelToken token() @trusted nothrow @nogcGet a cancellation token for this source.
void cancel() @safe nothrow @nogcRequest cancellation.
bool isCancelled() @property const @safe nothrow @nogcCheck if this source has been cancelled.

RAII-style cancellation scope.

A CancelGuard owns a CancelSource and automatically cancels it when the guard is destroyed (e.g. on function exit). This ensures cleanup happens even when exceptions or early returns bypass manual cancellation.

Use token to obtain a CancelToken and pass it to async operations. When the guard exits, all operations observing the token will see isCancelled == true.

Example:

{
    CancelGuard guard;
    // ... start async work with guard.token ...
} // guard destroyed — cancellation triggered automatically

Fields
CancelSource _source
Methods
CancelToken token() @trusted nothrow @nogcGet the cancellation token for this guard.
bool isCancelled() @property const @safe nothrow @nogcCheck if this guard has been cancelled.
void cancel() @safe nothrow @nogcManually cancel the guard before destruction.
void dispose() @safe nothrow @nogcDispose the guard, triggering cancellation if not already cancelled.
Destructors

Functions 1

fnR withCancel(R, P...)(R delegate(CancelToken, P) @safe fn, P args) @safeExecute a function with automatic cancellation propagation.