Permalink
Browse files

add error handler

  • Loading branch information...
1 parent 5ecb4dc commit cf46cfad2c8f1904933ec38212a96a4ebffa9538 @ben-lin ben-lin committed Nov 21, 2012
Showing with 31 additions and 2 deletions.
  1. +31 −2 lib/flow.js
View
@@ -97,18 +97,42 @@ var Flow = function (){
Flow.prototype = {
+/**
+ * Default error handler.
+ * @private
+ * @this {Flow}
+ * @param {Error} err Error to throw.
+ */
+ _error : function ( err ){
+ throw err;
+ },
+
+
+
+/**
+ * Check if the stack handler is the `next` handler.
+ * @private
+ * @this {Flow}
+ * @param {String} str The handler to be check.
+ */
_is_next : function ( str ){
return /self\[ '_' \+ next_type \]\.apply\( self, slice\.call\( arguments \)\);/g.test( str );
},
+
+
/**
* Call the current series function and remove it.
* @private
* @this {Flow}
* @param {Array} args Arguments to be passed to the current series function.
*/
_run_series : function ( args ){
- this._series.shift().apply( this, args );
+ try{
+ this._series.shift().apply( this, args );
+ }catch( err ){
+ this._error( err );
+ }
},
@@ -145,7 +169,6 @@ Flow.prototype = {
* @param {Array} args Arguments to be added to the current parallel function.
*/
_run_parallel : function ( args ){
-
var self = this;
var parallel_args = this._parallel_args.shift();
var args_form_last_task = args;
@@ -357,6 +380,12 @@ Flow.prototype = {
return this;
},
+ error : function ( callback ){
+ this._error = callback;
+
+ return this;
+ },
+
/**

0 comments on commit cf46cfa

Please sign in to comment.