Run.watch()
The .watch()
method allows you to monitor the execution of a workflow run, providing real-time updates on the status of steps.
Usage example
const run = await workflow.createRunAsync();
run.watch((event) => {
console.log(event?.payload?.currentStep?.id);
});
const result = await run.start({ inputData: { value: "initial data" } });
Parameters
callback:
(event: WatchEvent) => void
A callback function that is called whenever a step is completed or the workflow state changes. The event parameter contains: type ('watch'), payload (currentStep and workflowState), and eventTimestamp
type?:
'watch' | 'watch-v2'
= 'watch'
The type of watch events to listen for. 'watch' for step completion events, 'watch-v2' for data stream events
Returns
unwatch:
() => void
A function that can be called to stop watching the workflow run
Extended usage example
const run = await workflow.createRunAsync();
run.watch((event) => {
console.log(event?.payload?.currentStep?.id);
}, "watch");
const result = await run.start({ inputData: { value: "initial data" } });