batch
Advanced tools
Comparing version 0.0.3 to 0.1.0
0.1.0 / 2012-07-03 | ||
================== | ||
* add Emitter inheritance and emit "complete" [burcu] | ||
0.0.3 / 2012-06-02 | ||
@@ -3,0 +8,0 @@ ================== |
/** | ||
* Module dependencies. | ||
*/ | ||
var EventEmitter = require('events').EventEmitter; | ||
/** | ||
* Expose `Batch`. | ||
@@ -13,2 +19,3 @@ */ | ||
function Batch() { | ||
EventEmitter.call(this); | ||
this.fns = []; | ||
@@ -21,2 +28,8 @@ for (var i = 0, len = arguments.length; i < len; ++i) { | ||
/** | ||
* Inherit from `EventEmitter.prototype`. | ||
*/ | ||
Batch.prototype.__proto__ = EventEmitter.prototype; | ||
/** | ||
* Queue a function. | ||
@@ -44,3 +57,4 @@ * | ||
Batch.prototype.end = function(cb){ | ||
var pending = this.fns.length | ||
var that = this | ||
, pending = this.fns.length | ||
, results = [] | ||
@@ -55,3 +69,5 @@ , done; | ||
if (err) return done = true, cb(err); | ||
results[index] = res; | ||
that.emit('complete', res, index); | ||
--pending || cb(null, results); | ||
@@ -58,0 +74,0 @@ }); |
{ | ||
"name": "batch" | ||
, "version": "0.0.3" | ||
, "version": "0.1.0" | ||
, "description": "Simple async batch" | ||
, "keywords": [] | ||
, "author": "TJ Holowaychuk <tj@vision-media.ca>" | ||
@@ -12,3 +11,2 @@ , "dependencies": { | ||
, "main": "index" | ||
, "engines": { "node": "*" } | ||
} |
@@ -24,2 +24,6 @@ | ||
batch.on('complete', function(user, i){ | ||
// result of the ith job | ||
}); | ||
batch.end(function(err, users){ | ||
@@ -26,0 +30,0 @@ |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
3346
57
56
1