Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/moeriki/node-once-then
https://github.com/moeriki/node-once-then
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/moeriki/node-once-then
- Owner: moeriki
- License: mit
- Created: 2017-03-20T09:01:46.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-07-23T12:34:12.000Z (over 5 years ago)
- Last Synced: 2024-12-30T11:03:08.201Z (10 days ago)
- Language: JavaScript
- Size: 112 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
once-then
Add onceThen to your emitter to convert an event to a Promise.
## Installation
```
npm install --save once-then
```## Usage
```js
const EventEmitter = require('events').EventEmitter;
const onceThen = require('once-then');
````onceThen` works with the NodeJS event emitter or any events implementation that has its `once` method backwards compatible with NodeJS events.
```js
const emitter = new EventEmitter();onceThen(emitter, 'myEventName').then(() => {
//
});emitter.emit('myEventName');
```### Register
Register `onceThen` on an object.
```js
onceThen.register(EventEmitter.prototype);const emitter = new EventEmitter();
emitter.onceThen('myEventName').then(() => {
//
});emitter.emit('myEventName');
```