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

cacheKey
string
required

Should be a stable and unique cache key inside the run(). See resumability for more information.

event
object
required

Specify the options for the event to wait for.

name
string | string[]
required

The name(s) of the event to wait for.

schema
ZodTypeAny

An optional Zod schema to validate the event payload against. If omitted the event.payload will be typed as any

filter
EventFilter

An EventFilter to match against the event payload.

source
string

The source of the event to wait for. If omitted, the event can come from any source.

contextFilter
EventFilter

An EventFilter to match against the event context.

accountId
string

The account ID of the event to wait for. If omitted, the event can come from any account.

options
object

Specify the options for the event to wait for.

timeoutInSeconds
number

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

id
string
required

The ID of the event that was emitted.

name
string
required

The name of the event that was emitted.

payload
any
required

The payload of the event that was emitted.

context
any

The context of the event that was emitted.

timestamp
Date
required

The timestamp of the event that was emitted.

accountId
string

The account ID of the event that was emitted.

Was this page helpful?