event-emitter-promisify is a lightweight JavaScript and TypeScript utility library designed to convert Node.js `EventEmitter` instances into standard Promises. It enables developers to integrate asynchronous `async/await` syntax with traditional event-driven patterns, specifically by resolving a Promise when a success event (defaulting to 'end') is emitted, and rejecting it upon an 'error' event. The library provides a single, focused function, `promisifyEventEmitter`, which simplifies handling the lifecycle of event emitters in a Promise-based workflow. The current stable version is 1.1.0, released in February 2022. While functional and stable, the project exhibits an infrequent release cadence, with no major updates since its initial introduction. Its primary differentiation lies in offering a specialized solution for EventEmitters, distinguishing it from general-purpose promisification utilities like `util.promisify` that target Node.js-style callback functions.
npm install event-emitter-promisifyVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use `promisifyEventEmitter` with a simple Node.js Readable stream, collecting data and awaiting its completion.
Update `package.json` to depend on `event-emitter-promisify` and change all import statements from `@jeswr/promisify-event-emitter` to `event-emitter-promisify`.
Ensure your `EventEmitter` pipeline reliably emits an `end` event upon completion, or provide a second argument to `promisifyEventEmitter` to specify a custom event that signifies success and a return value.
Implement robust error handling within your `EventEmitter` producer to ensure that any failure condition results in an `error` event being emitted. Alternatively, introduce a timeout mechanism for the promise if hanging is a concern.
Ensure the variable passed to `promisifyEventEmitter` is an instance of `EventEmitter` or an object that implements the `on` method (e.g., a `Readable` stream, `net.Socket`, etc.).
Review the logic of your `EventEmitter` producer to verify that it eventually emits a 'end' event (or your specified custom success event) when its operation completes, or an 'error' event if a failure occurs. Debug the EventEmitter's event flow.
No dependency data recorded yet.