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.
options
object
Specify the options for the event to wait for.

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.
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
  }
);