Waits for any of the specified operating system events to occur

⚠️ NOTE: Requires an active event loop to process events

  • Returns a promise that resolves when any of the specified events occur.

    Type Parameters

    Parameters

    • names: T[]

      Array of event names to wait for

    • check: (event: T, ...args: Events[T]) => boolean = ...

      Optional function to filter events based on their name and arguments

    • timeout: number = 0

      Optional timeout in milliseconds. If 0, waits indefinitely

    Returns Promise<[T, ...Events[T][]]>

    A promise that resolves with a tuple of the event name and arguments

    If the timeout is reached before any of the events occur

    try {
    const [event, ...args] = await events.waitForAnyEvent(
    ['player_join', 'player_leave'],
    (event, ...args) => event === 'player_join' || args[0] === 'admin',
    10000
    );
    if (event === 'player_join') {
    console.log(`Player ${args[0]} joined`);
    } else {
    console.log(`Player ${args[0]} left`);
    }
    } catch (error) {
    console.log('Timed out waiting for player events');
    }