Skip to content

Commit b84f1cd

Browse files
committed
[refactoring] Catch error when first argument is an instance of Error
1 parent 0ab0ea3 commit b84f1cd

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

lib/flow.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ Flow.prototype = {
128128
* @param {Array} args Arguments to be passed to the current series function.
129129
*/
130130
_run_series : function ( args ){
131+
if( args.length && args[ 0 ] instanceof Error ){
132+
return this._error( args[ 0 ]);
133+
}
134+
131135
try{
132136
this._series.shift().apply( this, args );
133137
}catch( err ){

test/flow.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,5 +351,40 @@ module.exports = {
351351
callback();
352352
}, 150 );
353353
});
354+
},
355+
356+
'error handeling' : function ( callback ){
357+
var flow = new Flow( 5, 6, 7 );
358+
359+
flow.series( function ( x, y, z, next ){
360+
setTimeout( function (){
361+
x.should.equal( 7 );
362+
y.should.equal( 6 );
363+
z.should.equal( 7 );
364+
next( new Error( 'Error found' ));
365+
}, 200 );
366+
}, 7 ).
367+
368+
series( function ( x, y, z, next ){
369+
setTimeout( function (){
370+
x.should.equal( 11 );
371+
y.should.equal( 10 );
372+
z.should.equal( 55 );
373+
next( 1000 );
374+
}, 100 );
375+
}, 9, 10, 55 ).
376+
377+
error( function ( err ){
378+
console.log( 'error handeling', err );
379+
}).
380+
381+
end( function ( x ){
382+
setTimeout( function (){
383+
x.should.equal( 1000 );
384+
385+
console.log( 'this shouldn\t be seen' );
386+
callback();
387+
}, 150 );
388+
});
354389
}
355390
};

0 commit comments

Comments
 (0)