Socket
Socket
Sign inDemoInstall

thunkify-wrap

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

thunkify-wrap - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

test/event.js

7

History.md
n.n.n / 2014-03-05
==================
* add event in readme
* add test for event
* add event support
n.n.n / 2014-02-28

@@ -3,0 +10,0 @@ ==================

55

index.js

@@ -7,2 +7,3 @@ /**!

'use strict';
var EventEmitter = require('events').EventEmitter;

@@ -26,2 +27,6 @@ /**

if (input instanceof EventEmitter) {
return eventToThunk(input, ctx);
}
// thunkify object

@@ -59,3 +64,2 @@ if (type === 'object') {

* @return {Function}
* @api public
*/

@@ -91,1 +95,50 @@

}
/**
* wrap a event object to a thunk
* yield to wait the event emit `end`, `close`, `finish` or others
* @param {Event} e
* @param {Array} globalEvents
* @return {Function}
*/
function eventToThunk(e, globalEvents) {
globalEvents = globalEvents || ['end'];
return function (endEvents) {
var called = false;
endEvents = endEvents || globalEvents;
if (!Array.isArray(endEvents)) {
endEvents = [endEvents];
}
return function (done) {
// clean
function _done(err, data) {
e.removeListener('error', error);
endEvents.forEach(function (name) {
e.removeListener(name, end);
});
done(err, data);
}
function error(err) {
if (called) {
return;
}
called = true;
done(err);
}
function end(data) {
if (called) {
return;
}
called = true;
done(null, data);
}
e.once('error', error);
endEvents.forEach(function (name) {
e.once(name, end);
});
};
};
}

2

package.json
{
"name": "thunkify-wrap",
"version": "0.0.3",
"version": "0.0.4",
"repository": "dead-horse/node-thunkify-wrap",

@@ -5,0 +5,0 @@ "description": "Turn callbacks, arrays, generators, generator functions, and promises into a thunk",

@@ -35,2 +35,17 @@

## event support
you can pass an event object, give end event name list, wrap event to thunk like this
```
var e = new EventEmitter();
var end = thunkify(e, 'finish');
yield end();
or
yield.end(['close', 'end']); // will cover `finish` event
```
when specified events emitted, this generator will go on. see more in the source code.
## ctx

@@ -37,0 +52,0 @@

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