Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/moeriki/node-once-then


https://github.com/moeriki/node-once-then

Last synced: 7 days ago
JSON representation

Awesome Lists containing this project

README

        


once-then


Add onceThen to your emitter to convert an event to a Promise.




npm version


Build Status


Coverage Status


dependencies Status

## 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');
```