Function eventRace

Subscribes to events on target, returning the event data from the first event that fires.

By default waits a maximum of 1 minute.

Automatically unsubscribes on success or failure (ie. timeout)

// Event will be data from either event, whichever fires first
// Exception is thrown if neither fires within 1 second
const event = await eventRace(document.body, [`pointermove`, `pointerdown`], { timeout: 1000 });
  • Parameters

    • target: EventTarget

      Event source

    • eventNames: string[]

      Event name(s)

    • options: Partial<{
          signal: AbortSignal;
          timeout: Interval;
      }> = {}

      Options

    Returns Promise<Event>