Class: CancellationScope
workflow.CancellationScope
In the SDK, Workflows are represented internally by a tree of scopes where the execute
function runs in the root scope.
Cancellation propagates from outer scopes to inner ones and is handled by catching CancelledFailures
thrown by cancellable operations (see below).
Scopes are created using the CancellationScope
constructor or the static helper methods
cancellable, nonCancellable and withTimeout.
When a CancellationScope
is cancelled, it will propagate cancellation any child scopes and any cancellable
operations created within it, such as:
Example
await CancellationScope.cancellable(async () => {
const promise = someActivity();
CancellationScope.current().cancel(); // Cancels the activity
await promise; // Throws `ActivityFailure` with `cause` set to `CancelledFailure`
});
Example
const scope = new CancellationScope();
const promise = scope.run(someActivity);
scope.cancel(); // Cancels the activity
await promise; // Throws `ActivityFailure` with `cause` set to `CancelledFailure`