Skip to content

[TRI-1275] Add io.waitForNextEvent that resumes once a matching event is found #472

@ericallam

Description

@ericallam

It would be nice to support the following io task in a job run:

const event = await io.waitForNextEvent("✋", { name: "opt-in", filter: { userId: [payload.userId] })

We could also add a continueAfter parameter that would return undefined if the event isn't received in time:

const event = await io.waitForNextEvent("✋", {
  name: "opt-in",
  filter: { userId: [payload.userId] },
  continueAfter: 60 * 10,
});

Type Safety

Currently the event payload type in eventTrigger is inferred via an optionally passed in schema:

eventTrigger({
    name: "foo.event",
    schema: z.object({
      userId: z.string(),
      delay: z.number(),
    }),
  })

We could add support for a schema to waitForNextEvent as well:

const event = await io.waitForNextEvent("✋", {
  name: "opt-in",
  filter: { userId: [payload.userId] },
  continueAfter: 60 * 10,
  schema: z.object({ userId: z.string() })
});

Once we add support for an Event Catalog (#251) the event payload type would be automatically inferred based on it's name

TRI-1275

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions