Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

await-event

Package Overview
Dependencies
Maintainers
5
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

await-event - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

5

History.md
2.1.0 / 2017-03-24
==================
* feat: support await(emitter, event) (#4)
2.0.0 / 2017-02-16

@@ -3,0 +8,0 @@ ==================

9

index.js
'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))
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc