Skip to main content
CrystalFlow provides comprehensive cancellation support for stopping workflow execution when needed.

Cancellation Mechanisms

Timeout

Automatic cancellation after time limit

User-Initiated

Manual cancellation via API

External Signal

AbortController/AbortSignal support

Mid-Node

Check cancellation during long operations

Timeout-Based Cancellation

Set a timeout when executing:

User-Initiated Cancellation

Cancel an execution manually:

External Signal Cancellation

Use AbortController for external cancellation:

Cancellation Reasons

CancellationReason
Execution exceeded timeout limit
CancellationReason
User explicitly cancelled via API
CancellationReason
Cancelled via AbortController/AbortSignal
CancellationReason
Resource constraints (reserved for future use)

Mid-Node Cancellation

Nodes can check for cancellation during long operations:

Cancellation Events

Listen to cancellation events:

Cancel All Executions

Cancel all active executions:

Check Active Executions

Check if an execution is still running:

React Integration

Implement cancellation in React components:

Graceful Shutdown

Implement graceful shutdown with cleanup:
Node Cleanup: The cleanup() method for node-level cleanup is planned for a future release.

Best Practices

Always set timeouts to prevent workflows from running indefinitely.
For nodes with loops, call checkCancellation() in each iteration.
Cancel network requests, close connections, and clear timers when cancelled.
Show cancellation status and allow users to cancel long operations.
Catch cancellation errors and clean up appropriately.

Complete Example

Next Steps

Error Handling

Handle execution errors

Execution & Events

Master the event system

Executor API

Complete Executor reference

Node API

Node class reference