Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/inikulin/promisify-event

Promisify EventEmitter's event.
https://github.com/inikulin/promisify-event

Last synced: 14 days ago
JSON representation

Promisify EventEmitter's event.

Awesome Lists containing this project

README

        

# promisify-event
[![Build Status](https://api.travis-ci.org/inikulin/promisify-event.svg)](https://travis-ci.org/inikulin/promisify-event)

*Promisify EventEmitter's event.*

## Install
```
npm install promisify-event
```

## Usage
```js
const promisifyEvent = require('promisify-event');

// Promisify server's `listening` event:
promisifyEvent(server, `listening`).then(() => {
// ...
});

// Promisify `error` event. `error` event always rejects the promise:
promisifyEvent(server, 'error').catch(() => {
// ...
});

// Cancel event subscription and promise (it will be never fulfilled):
var listeningPromise = promisifyEvent(server, `listening`);

listeningPromise.cancel();

listeningPromise.then(() => {
// Will never happen
});

```

## Author
[Ivan Nikulin](https://github.com/inikulin) ([email protected])