Called when a listener throws, instead of the default asynchronous rethrow. Set this to log, count, or fail loudly in tests.
Subscribe to an event. Returns an unsubscribe function, so a consumer can hold one disposer rather than keeping the listener reference around:
const off = world.events.on('cellClick', onClick);
// later
off();
Adding the same listener twice is a no-op — listeners are a set, so an event is never delivered to the same function twice.
Subscribe until the next time this event fires, then unsubscribe automatically.
Deliver an event to every current listener. Returns true if anyone was listening — useful to skip building an expensive payload:
if (events.listenerCount('chunkLoaded') > 0) events.emit('chunkLoaded', buildPayload());
How many listeners are subscribed to an event — 0 if none.
Drop every listener for one event type, or (with no argument) for all of them.
Optionaltype: K
A small typed event emitter, generic over an event map — an interface whose keys are event names and whose values are that event's payload type:
Two behaviours matter for anything driven from a render loop:
emititerates a copy of the listener set, so a listener that subscribes or unsubscribes while the event is being delivered doesn't change who receives this event. Without it, a handler that removes itself would make the iterator skip the next listener.window.onerror/unhandledExceptionwith its original stack. Set onError to route it somewhere else instead.