1.0.4 • Published 3 years ago

@async-generator/emitter-on v1.0.4

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

returns an that iterates eventName events emitted by the emitter

This is a ponyfill for NodeJS's EventEmitter.on

installation

> npm i @async-generator/emitter-on

usage

const on = require("@async-generator/emitter-on");

const emitter = new EventEmitter();

for await (const item of on(emitter, "data")) {
  console.log(item); // will log { id: 1 }, { id: 2 } etc.
}

// somewhere else in your code
emitter.emit("data", { id: 1 });
emitter.emit("data", { id: 2 });
emitter.emit("data", { id: 3 });
emitter.emit("data", { id: 4 });