@seedcord/event-emitter
v0.1.3
Published
Typed event emitter with waitFor, for Node and the edge
Maintainers
Readme
About
TypedEventEmitter ties each event name to its payload tuple, so a typo in a name or a wrong argument is a compile error. It carries no dependency on node:events. It runs on Cloudflare Workers and other edge runtimes alongside Node.
waitFor resolves with the payload of the next matching event. It rejects with a WaitForError when the timeout elapses or the AbortSignal fires, and error.reason says which of the two happened.
Until v1.0.0, minor versions can break.
Installation
Your transport already re-exports this. It also stands alone with no seedcord dependency:
pnpm add @seedcord/event-emitterUsage
import { TypedEventEmitter } from '@seedcord/event-emitter';
interface Events {
ready: [startedAt: number];
failed: [error: Error];
}
const bus = new TypedEventEmitter<Events>();
bus.on('ready', (startedAt) => {
// startedAt is a number
});
const [startedAt] = await bus.waitFor('ready', { timeoutMs: 5_000 });waitFor also takes a filter, which resolves on the first payload the filter accepts.
