Protected
offRegisters an event handler that will be called when the specified event is dispatched.
The name of the event to listen for
The function to call when the event occurs
Optional function to filter events based on their arguments
If true, the handler will be removed after being called once
A function that can be called to remove the event handler
Registers a one-time event handler that will be automatically removed after being called once.
A function that can be called to remove the event handler
Returns a promise that resolves when any of the specified events occur.
A promise that resolves with a tuple of the event name and arguments
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');
}
Returns a promise that resolves when the specified event occurs.
A promise that resolves with the event arguments
A type-safe event management system that allows for registering, dispatching, and waiting for events.
Example