Waits for a specific operating system event to occur

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

  • Returns a promise that resolves when the specified event occurs.

    Type Parameters

    Parameters

    • name: T

      The name of the event to wait for

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

      Optional function to filter events based on their arguments

    • timeout: number = 0

      Optional timeout in milliseconds. If 0, waits indefinitely

    Returns Promise<Events[T]>

    A promise that resolves with the event arguments

    If the timeout is reached before the event occurs

    try {
    const [itemId, count] = await events.waitForEvent(
    'item_pickup',
    (itemId) => itemId === 64, // Wait for diamond pickup
    5000 // Timeout after 5 seconds
    );
    console.log(`Picked up ${count} diamonds!`);
    } catch (error) {
    console.log('Timed out waiting for diamond pickup');
    }