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
Reason an operation was terminated.
Shared state for cancellation tracking.
This struct is intended to be used with CancelSource and CancelToken.
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.
The owner of a cancellation state.
A source can be used to trigger cancellation and provide tokens to multiple asynchronous operations.
private CancelState _stateRAII-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 automaticallyCancelSource _sourcevoid dispose() @safe nothrow @nogcDispose the guard, triggering cancellation if not already cancelled.Functions 1
R withCancel(R, P...)(R delegate(CancelToken, P) @safe fn, P args) @safeExecute a function with automatic cancellation propagation.