await-event
Advanced tools
Comparing version 2.0.0 to 2.1.0
2.1.0 / 2017-03-24 | ||
================== | ||
* feat: support await(emitter, event) (#4) | ||
2.0.0 / 2017-02-16 | ||
@@ -3,0 +8,0 @@ ================== |
'use strict' | ||
module.exports = function(event) { | ||
module.exports = function(emitter, event) { | ||
if (typeof emitter === 'string') { | ||
event = emitter | ||
emitter = this | ||
} | ||
return new Promise((resolve, reject) => { | ||
const done = event === 'error' ? reject : resolve | ||
this.once(event, done) | ||
emitter.once(event, done) | ||
}) | ||
} |
{ | ||
"name": "await-event", | ||
"description": "yield an event with generators", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Jonathan Ong", |
@@ -22,5 +22,28 @@ # Await Event | ||
var chunk = yield stream.await('data') | ||
})() | ||
}).catch(noop) | ||
stream.write('some chunk') | ||
``` | ||
You can use awaitEvent without attach on an event emitter: | ||
```js | ||
var EventEmitter = require('event') | ||
var emitter = new EventEmitter() | ||
co(function*() { | ||
yield awaitEvent(emitter, 'ready') | ||
}).catch(noop) | ||
``` | ||
When use this for `error` event, it will reject once `error` event emitted: | ||
```js | ||
var EventEmitter = require('event') | ||
var emitter = new EventEmitter() | ||
co(function*() { | ||
// it will throw when `error` event emitted | ||
yield awaitEvent(emitter, 'error') | ||
}).catch(err => console.error(err.stack)) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
3288
11
49
1