Wondering what’s next for npm?Check out our public roadmap! »

event-awaiter
TypeScript icon, indicating that this package has built-in type declarations

1.1.2 • Public • Published

Event Awaiter


Do you have a problem with asynchronous operations where you need to wait for some other event to finish before you continue processing the current one? This package solves this problem.

The package can be used in browser (using EventTarget) or nodejs (using EventEmitter)


Installation

npm i event-awaiter


Usage

const { getEventAwaiter } = require("event-awaiter");
const ea = getEventAwaiter({
  timeout: 20000 // number of milliseconds after event will get rejected
});

const key = "uniqueKey";

const needToBeAwaited = async () => {
  const payload = await ea.setupListener(key); // will be awaited
  console.log(payload);
}

needToBeAwaited();
ea.dispatchEvent(key, "hello world!");

Common Use Cases

  • WebSocket events
  • RabbitMQ events

The package doesn't support IE

Install

npm i event-awaiter

DownloadsWeekly Downloads

54

Version

1.1.2

License

ISC

Unpacked Size

19.1 kB

Total Files

36

Last publish

Collaborators

  • avatar