eetase
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/eetase package

7.0.1 • Public • Published

eetase

EventEmitter to AsyncStreamEmitter converter.

Allows an EventEmitter (https://nodejs.org/api/events.html#events_class_eventemitter) to be used as an AsyncStreamEmitter (https://github.com/SocketCluster/async-stream-emitter). Keeps original EventEmitter functionality.

Installation

npm install eetase

Usage example

const eetase = require('eetase');
const http = require('http');

// The Node.js HTTP server is an EventEmitter.
// Normally works using server.on('request', handler);
let server = http.createServer();

// Mutates the server instance but doesn't touch
// the instance's prototype.
eetase(server);

// ...

// The Node.js HTTP server now works as an
// AsyncStreamEmitter
(async () => {
  // Use array destructuring to get the req object.
  // This is needed because emitter.emit(eventName, ...)
  // can have multiple arguments.
  for await (let [req] of server.listener('request')) {
    // ...
  }
})();

Package Sidebar

Install

npm i eetase

Weekly Downloads

660

Version

7.0.1

License

MIT

Unpacked Size

6.39 kB

Total Files

5

Last publish

Collaborators

  • topcloudsystems