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

1.1.3 • 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

Package Sidebar

Install

npm i event-awaiter

Weekly Downloads

1

Version

1.1.3

License

ISC

Unpacked Size

20.6 kB

Total Files

38

Last publish

Collaborators

  • repugraf