0.4.0 • Published 1 year ago

@yingyeothon/event-broker v0.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Event Broker

A simple event broker with asynchronous handlers.

Usage

import { EventBroker } from "@yingyeothonevent-broker";

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

class Reader extends EventBroker<IReaderEventMap> {
  public async start() {
    try {
      while (true) {
        const buffer = this.readMore();
        if (!buffer) {
          break;
        }
        await this.fire("read", buffer);
      }
    } catch (error) {
      await this.fire("error", error);
    }
  }
}

new Reader()
  .on("read", console.log)
  .on("error", console.error)
  .start();

Of course, we don't need to await a result from fire method if there is no asynchronous handler.

License

MIT

0.4.0

1 year ago

0.3.0

4 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago