Controls how cancellation propagates through workflow code.

When a workflow is cancelled via handle.cancel(), the next durable operation (sleep, proxyActivities, executeChild, condition, continueAsNew) throws a CancelledFailure. Use CancellationScope.nonCancellable(fn) to shield cleanup code from this behavior — durable operations inside the scope will execute normally even when cancellation is pending.

import { Durable } from '@hotmeshio/hotmesh';
const { CancellationScope, isCancellation } = Durable.workflow;

export async function orderWorkflow(orderId: string): Promise<string> {
const acts = Durable.workflow.proxyActivities<typeof activities>({ ... });

try {
await acts.chargePayment(orderId);
await Durable.workflow.sleep('7 days');
await acts.shipOrder(orderId);
} catch (err) {
if (isCancellation(err)) {
// Shield cleanup from further cancellation
await CancellationScope.nonCancellable(async () => {
await acts.refundPayment(orderId);
await acts.notifyCustomer(orderId, 'Order cancelled');
});
return 'cancelled';
}
throw err;
}
return 'shipped';
}

Constructors

Methods

Constructors

Methods

  • Execute fn with cancellation suppressed. Durable operations inside the callback will not throw CancelledFailure even if the workflow has a pending cancellation request. Use this for cleanup logic (refunds, notifications, audit logs) that must complete regardless of cancellation state.

    Type Parameters

    • T

    Parameters

    • fn: (() => Promise<T>)

      The async function to execute without cancellation.

        • (): Promise<T>
        • Returns Promise<T>

    Returns Promise<T>

    The return value of fn.