npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@yingyeothon/event-broker

v2.6.0

Published

Type-safe async event broker with add/remove/once listener semantics.

Readme

@yingyeothon/event-broker

A tiny, type-safe event broker: define your events as a TypeScript event map, create a broker with createEventBroker, and fire events into synchronous or asynchronous handlers. Handlers run in registration order and each async handler is awaited before the next one runs.

Firing an event is a sequencing point: handlers run in registration order and each is awaited before the next.

sequenceDiagram
  participant P as your code
  participant B as the broker
  participant H1 as handler 1
  participant H2 as handler 2
  P->>B: fire
  B->>H1: await
  H1-->>B: done
  B->>H2: await
  H2-->>B: done
  B-->>P: resolves only now

Install

npm install @yingyeothon/event-broker

Usage

ESM:

import { createEventBroker } from "@yingyeothon/event-broker";

interface ReaderEventMap {
  read: string;
  error: Error;
}

const reader = createEventBroker<ReaderEventMap>();
reader.on("read", console.log).once("error", console.error);

try {
  for (const line of ["hello", "world"]) {
    await reader.fire("read", line);
  }
} catch (error) {
  await reader.fire("error", error as Error);
}

CJS:

const { createEventBroker } = require("@yingyeothon/event-broker");

const ticker = createEventBroker();
const onTick = (value) => console.log("tick", value);
ticker.on("tick", onTick);
ticker.fire("tick", 1).then(() => ticker.off("tick", onTick));

There is no need to await the result of fire when every handler is synchronous.

Public API

  • createEventBroker<E>() — factory that returns an EventBroker<E>.
  • EventBroker<E> — interface. Listener registration via on(name, handler), once(name, handler), and off(name, handler), each returning the broker for chaining. Events are dispatched with fire(name, event), which awaits handlers one by one in registration order and resolves to true when at least one handler was registered. A handler that throws (or rejects) makes fire reject and skips the remaining handlers.
  • EventListenable<E> — interface with the listener-facing surface: on, once, and off.
  • EventHandler<T> — type of an event handler: (event: T) => unknown, where a returned promise is awaited.

Migrating from the legacy package

  • EventBroker<E> is now an interface, not a class: replace new EventBroker() (or subclassing) with createEventBroker<E>(). fire is part of the public surface instead of a protected method, so dispatching no longer requires a subclass.
  • once and off are new; the legacy broker only supported on.
  • EventListenable<E> now declares once and off in addition to on, so custom implementations must provide all three.
  • Handlers are snapshotted per fire call: handlers added or removed during dispatch take effect from the next fire, whereas the legacy broker iterated the live handler array.
  • fire resolves to false when the event has no remaining handlers (the legacy broker returned false only when the event name had never been registered).