node.js - Node Async Waterfall with generic callback handler -
i have inherited application relies entirely on async.waterfall 1 of controllers. don't want re-write whole thing, in fixing couple items want convert callback param more generic handler.
right example function looks below (same pattern exists dozen more functions)
function create(data, callbackparent) { async.waterfall( [ function(callback) { if (!interface) { return init(callback); } else { return callback(null); } }, function(callback) { return interface.create(data, callback); } ], (error, result) => { if (error) { const codeindex = error.indexof('statuscode=') + 'statuscode='.length; const errorstatuscode = error.slice(codeindex, codeindex + 3); if(errorstatuscode == 401) { reconnect(callbackparent); } else { return callbackparent(error); } } return callbackparent(null, result); } ); } no problem , works great; however, notice callback there. trying move generic function handleresponse(error, result) example:
function create(data, callbackparent) { async.waterfall( [ function(callback) { if (!interface) { return init(callback); } else { return callback(null); } }, function(callback) { return interface.create(data, callback); } ], (error, result) => handleresponse ); } i've tried various combos of syntax above either blows up, or lose context callbackparent.
- how can construct callback async.waterfall array separate , generic handler?
Comments
Post a Comment