batch
Advanced tools
Comparing version 0.1.1 to 0.2.0
0.2.0 / 2012-10-04 | ||
================== | ||
* add progress events. Closes #5 (__BREAKING CHANGE__) | ||
0.1.1 / 2012-07-03 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -55,4 +55,5 @@ | ||
Batch.prototype.end = function(cb){ | ||
var that = this | ||
, pending = this.fns.length | ||
var self = this | ||
, total = this.fns.length | ||
, pending = total | ||
, results = [] | ||
@@ -63,9 +64,24 @@ , done; | ||
this.fns.forEach(function(fn, index){ | ||
this.fns.forEach(function(fn, i){ | ||
var start = new Date; | ||
fn(function(err, res){ | ||
if (done) return; | ||
if (err) return done = true, cb(err); | ||
var complete = total - pending + 1; | ||
var end = new Date; | ||
results[index] = res; | ||
that.emit('progress', res, index); | ||
results[i] = res; | ||
self.emit('progress', { | ||
index: i, | ||
value: res, | ||
pending: pending, | ||
total: total, | ||
complete: complete, | ||
percent: complete / total * 100 | 0, | ||
start: start, | ||
end: end, | ||
duration: end - start | ||
}); | ||
--pending || cb(null, results); | ||
@@ -72,0 +88,0 @@ }); |
{ | ||
"name": "batch" | ||
, "version": "0.1.1" | ||
, "version": "0.2.0" | ||
, "description": "Simple async batch" | ||
@@ -5,0 +5,0 @@ , "author": "TJ Holowaychuk <tj@vision-media.ca>" |
@@ -24,4 +24,4 @@ | ||
batch.on('progress', function(user, i){ | ||
// result of the ith job | ||
batch.on('progress', function(e){ | ||
}); | ||
@@ -34,2 +34,18 @@ | ||
### Progress events | ||
Contain the "job" index, response value, duration information, and completion data. | ||
```js | ||
{ index: 1, | ||
value: 'bar', | ||
pending: 2, | ||
total: 3, | ||
complete: 2, | ||
percent: 66, | ||
start: Thu Oct 04 2012 12:25:53 GMT-0700 (PDT), | ||
end: Thu Oct 04 2012 12:25:53 GMT-0700 (PDT), | ||
duration: 0 } | ||
``` | ||
## License | ||
@@ -36,0 +52,0 @@ |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
4150
71
72
0