Skip to content

ChainGraph API Documentation / @badaitech/chaingraph-types / createTypedExecutionHandler

Function: createTypedExecutionHandler()

createTypedExecutionHandler<T>(type, handler): ExecutionEventHandler<T>

Defined in: packages/chaingraph-types/src/flow/execution-handlers.ts:139

Helper function to create a strongly-typed handler for a specific execution event type

Type Parameters

T

T extends ExecutionEventEnum

Parameters

type

T

Execution event type

handler

ExecutionEventHandler<T>

Handler function for the event

Returns

ExecutionEventHandler<T>

Typed event handler

Example

typescript
const handleNodeStarted = createTypedExecutionHandler(
  ExecutionEventEnum.NODE_STARTED,
  (data, context) => {
    console.log('Node started:', data.node.id)
    console.log('Execution ID:', context.executionId)
  }
)

// Type-safe usage in handler map
const handlers: ExecutionEventHandlerMap = {
  [ExecutionEventEnum.NODE_STARTED]: handleNodeStarted
}

Licensed under BUSL-1.1