io.waitForEvent()
io.waitForEvent()
waits for the next event to be emitted, and returns the event data
const event = await io.waitForEvent(
"wait",
{
name: "my.event",
schema: z.object({
id: z.string(),
createdAt: z.coerce.date(),
isAdmin: z.boolean(),
}),
filter: {
isAdmin: [true], // Only wait for events where isAdmin is true
},
},
{
timeoutInSeconds: 60 * 60, // Wait for up to an hour
}
);
Parameters
Should be a stable and unique cache key inside the run()
. See
resumability for more information.
Specify the options for the event to wait for.
The name(s) of the event to wait for.
An optional Zod schema to validate the event payload against. If omitted the event.payload
will be typed as any
An EventFilter to match against the event payload.
The source of the event to wait for. If omitted, the event can come from any source.
An EventFilter to match against the event context.
The account ID of the event to wait for. If omitted, the event can come from any account.
Specify the options for the event to wait for.
The amount of time to wait for the event to be emitted before timing out. The default timeout is 1 hour and the maximum timeout is 1 year. If the timeout is reached, the task will fail with an error message and the run will be exited.
Returns
The ID of the event that was emitted.
The name of the event that was emitted.
The payload of the event that was emitted.
The context of the event that was emitted.
The timestamp of the event that was emitted.
The account ID of the event that was emitted.
Was this page helpful?
const event = await io.waitForEvent(
"wait",
{
name: "my.event",
schema: z.object({
id: z.string(),
createdAt: z.coerce.date(),
isAdmin: z.boolean(),
}),
filter: {
isAdmin: [true], // Only wait for events where isAdmin is true
},
},
{
timeoutInSeconds: 60 * 60, // Wait for up to an hour
}
);