Skip to content

Commit c07fc41

Browse files
committed
error events now too have job, jobIndex and totalJobs properties
1 parent 185a9d8 commit c07fc41

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

index.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var from2 = require('from2');
2+
var extend = require('extend');
23

34
// jobs is an array of function(next)
45
// returns a Stream that emits 2 data events per job
@@ -11,18 +12,16 @@ module.exports = function(jobs) {
1112
return from2.obj(function read(size, next) {
1213
if (jobs.length <= 0) return this.push(null);
1314
var job = jobs.shift();
14-
this.push({
15+
var ctx = {
1516
job: job,
16-
totalJobs: totalJobs,
17-
jobIndex: jobIndex
18-
});
17+
jobIndex: jobIndex,
18+
totalJobs: totalJobs
19+
};
20+
this.push(ctx);
1921
job(function(err, data) {
20-
next(err, {
21-
job:job,
22-
totalJobs: totalJobs,
23-
jobIndex: jobIndex++,
24-
result: data
25-
});
22+
++jobIndex;
23+
if (err) extend(err, ctx);
24+
next(err, extend({result: data}, ctx));
2625
});
2726
});
2827
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"author": "Jan Bölsche <[email protected]> (http://regular.codes)",
1818
"license": "ISC",
1919
"dependencies": {
20+
"extend": "^2.0.1",
2021
"from2": "^1.3.0"
2122
},
2223
"devDependencies": {

0 commit comments

Comments
 (0)