Permalink
Browse files

add .start, .end, and .duration properties

  • Loading branch information...
1 parent 72d0bcc commit 7fe1f59620732e2711f0d50e15810df61a40a671 @tj tj committed Oct 4, 2012
Showing with 12 additions and 3 deletions.
  1. +5 −2 Readme.md
  2. +6 −1 lib/batch.js
  3. +1 −0 test/batch.js
View
@@ -32,15 +32,18 @@ batch.end(function(err, users){
### Progress events
- Contain the "job" index, response value, and completion data.
+ Contain the "job" index, response value, duration information, and completion data.
```js
{ index: 1,
value: 'bar',
pending: 2,
total: 3,
complete: 2,
- percent: 66 }
+ 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
View
@@ -61,10 +61,12 @@ Batch.prototype.end = function(cb){
if (!this.fns.length) return cb(null, results);
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[i] = res;
@@ -74,7 +76,10 @@ Batch.prototype.end = function(cb){
pending: pending,
total: total,
complete: complete,
- percent: complete / total * 100 | 0
+ percent: complete / total * 100 | 0,
+ start: start,
+ end: end,
+ duration: end - start
});
--pending || cb(null, results);
View
@@ -73,6 +73,7 @@ describe('Batch', function(){
e.total.should.be.a('number');
e.complete.should.be.a('number');
e.pending.should.be.a('number');
+ e.duration.should.be.a('number');
break;
case 1:
e.value.should.equal('bar');

0 comments on commit 7fe1f59

Please sign in to comment.