Executor class orchestrates workflow execution with events and state management.
Class: Executor
Methods
execute()
Execute a workflow with options.Workflow
Workflow instance to execute.
ExecutionOptions
Optional execution configuration:
timeout?: number- Maximum execution time (ms)variables?: Record<string, any>- Workflow variablesabortSignal?: AbortSignal- External cancellation signal
ExecutionResult.
Example:
cancel()
Cancel a specific execution.string
Execution ID to cancel.
CancellationReason
Cancellation reason (default:
CancellationReason.UserCancelled).cancelAll()
Cancel all active executions.CancellationReason
Cancellation reason (default:
CancellationReason.UserCancelled).isExecutionActive()
Check if an execution is currently running.string
Execution ID to check.
true if execution is active, false otherwise.
Example:
Events
The Executor emits events throughout the execution lifecycle. All event listeners can be synchronous or asynchronous.beforeExecute
Emitted before workflow execution starts.ExecutionContext
Execution context with
executionId, workflowId, variables, etc.afterExecute
Emitted after workflow execution completes.ExecutionResult
Complete execution result.
onNodeStart
Emitted when a node starts executing.string
Node ID.
Node
Node instance.
onNodeComplete
Emitted when a node completes successfully.string
Node ID.
NodeExecutionResult
Node execution result with outputs, timing, etc.
onNodeError
Emitted when a node fails.string
Node ID.
Error
Error that occurred.
onError
Emitted when workflow execution fails.Error
Error that caused workflow failure.
onCancellation
Emitted when execution is cancelled.string
Cancelled execution ID.
CancellationReason
Cancellation reason.
Date
Timestamp of cancellation.
Types
ExecutionOptions
ExecutionResult
NodeExecutionResult
ExecutionContext
CancellationReason
Usage Examples
Basic Execution
With Events
Async Event Handlers
With Timeout
With Cancellation
With AbortSignal
Progress Tracking
Error Recovery
Related
Execution & Events
Master the execution system
Cancellation
Learn about cancellation
Error Handling
Handle execution errors
Workflow API
Workflow class reference