Workflow.sendEvent()
The .sendEvent()
resumes execution when an event is sent.
Usage example
run.sendEvent('event-name', { value: "data" });
Parameters
eventName:
string
The name of the event to send
step:
Step
The step to resume after the event is sent
Returns
workflow:
Workflow
The workflow instance for method chaining
Extended usage example
import { mastra } from "./mastra";
const run = await mastra.getWorkflow("testWorkflow").createRunAsync();
const result = run.start({
inputData: {
value: "hello"
}
});
setTimeout(() => {
run.sendEvent("event-name", { value: "from event" });
}, 3000);
In this example, avoid using
await run.start()
directly, as it would block sending the event before the workflow reaches its waiting state.