strict-event-emitter-once
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

strict-event-emitter-once

NPM Package Build Status

A typed implementation of Node.js events.once(emitter, name) for use with strict-event-emitter-types.

Creates a Promise that is fulfilled when the EventEmitter emits the given event.

Example usage

import { once } from 'strict-event-emitter-once';
 
// setup typed event emitter
import { StrictEventEmitter } from 'strict-event-emitter-types';
import { EventEmitter } from 'events';
 
// define your events
interface Events {
  request: (request: Request, response: Response) => void;
  done: void;
}
 
// create strict event emitter types
const ee: StrictEventEmitter<EventEmitter, Events> = new EventEmitter;
 
// await for an event
const [request, response] = await once(ee, 'request');
 
// await for an event that matches criteria
const [request, response] = await once(ee, 'request', (req, res) => {
  return req.url === '/';
});
 

LICENSE MIT

Package Sidebar

Install

npm i strict-event-emitter-once

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

8.24 kB

Total Files

8

Last publish

Collaborators

  • zone117x