withCancel

fnR withCancel(R, P...)(R delegate(CancelToken, P) @safe fn, P args) @safe

Execute a function with automatic cancellation propagation.

Creates a CancelGuard, passes its token to the provided function, and cancels the guard when the function returns. The cancellation happens regardless of how the function exits (normal return, exception, or early return).

Parameters

fnFunction to execute. Receives a CancelToken as the first argument.
argsAdditional arguments forwarded to fn.

Returns

The value returned by fn.