Socket
Socket
Sign inDemoInstall

batch

Package Overview
Dependencies
77
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.2.0

5

History.md
0.2.0 / 2012-10-04
==================
* add progress events. Closes #5 (__BREAKING CHANGE__)
0.1.1 / 2012-07-03

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

26

lib/batch.js

@@ -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 @@ });

2

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc