Skip to content

Package

event-emitter v0.2.0

Changelog

seedcordseedcord

The whole Discord bot, typed end to end

Website · Guide · Reference · Discord

npm node bun license

About

@seedcord/event-emitter exports TypedEventEmitter, which ties each event name to its payload types. A typo in an event name or a wrong argument is a compile error. It imports nothing from Node, so it runs on Node, Bun, and Cloudflare Workers.

Both seedcord transports depend on it and re-export it, and a bot's this.core.bus is one. Install it directly for a typed emitter in any project. It has no dependencies.

seedcord is pre-1.0, so a minor version can break your code. Each release's changelog says what changed and how to update.

Installation

pnpm add @seedcord/event-emitter

Usage

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 resolves with the next payload for that event. It rejects with a WaitForError when timeoutMs passes or a signal aborts.