p-event
Advanced tools
Comparing version 1.1.0 to 1.2.0
'use strict'; | ||
const pTimeout = require('p-timeout'); | ||
module.exports = (emitter, event, opts) => { | ||
@@ -58,3 +60,7 @@ let cancel; | ||
if (typeof opts.timeout === 'number') { | ||
return pTimeout(ret, opts.timeout); | ||
} | ||
return ret; | ||
}; |
{ | ||
"name": "p-event", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Promisify an event by waiting for it to be emitted", | ||
@@ -44,2 +44,5 @@ "license": "MIT", | ||
], | ||
"dependencies": { | ||
"p-timeout": "^1.1.1" | ||
}, | ||
"devDependencies": { | ||
@@ -46,0 +49,0 @@ "ava": "*", |
@@ -7,3 +7,5 @@ # p-event [![Build Status](https://travis-ci.org/sindresorhus/p-event.svg?branch=master)](https://travis-ci.org/sindresorhus/p-event) | ||
If you want multiple individual events as they are emitted, this module is not for you, as a Promise is a single value. Instead, just continue using event callback or use [Observables](https://medium.com/@benlesh/learning-observable-by-building-observable-d5da57405d87). | ||
## Install | ||
@@ -82,3 +84,3 @@ | ||
By default, the promisified function will only return the first argument from the callback, which works fine for most APIs. This option can be useful for modules like `kue` that return multiple arguments. Turning this on will make it return an array of all arguments from the callback, instead of just the first argument. This also applies to rejections. | ||
By default, the promisified function will only return the first argument from the event callback, which works fine for most APIs. This option can be useful for APIs that return multiple arguments in the callback. Turning this on will make it return an array of all arguments from the callback, instead of just the first argument. This also applies to rejections. | ||
@@ -88,8 +90,6 @@ Example: | ||
```js | ||
const kue = require('kue'); | ||
const pEvent = require('p-event'); | ||
const emitter = require('./some-event-emitter'); | ||
const queue = kue.createQueue(); | ||
pEvent(queue, 'job enqueue', {multiArgs: true}).then(result => { | ||
pEvent(emitter, 'finish', {multiArgs: true}).then(result => { | ||
const [id, type] = result; | ||
@@ -99,3 +99,10 @@ }); | ||
##### timeout | ||
Type: `Number`<br> | ||
Default: `Infinity` | ||
Time in milliseconds before timing out. | ||
## Before and after | ||
@@ -102,0 +109,0 @@ |
7279
49
161
1
+ Addedp-timeout@^1.1.1
+ Addedp-finally@1.0.0(transitive)
+ Addedp-timeout@1.2.1(transitive)