node.js - Using 'async' and neglecting to invoke 'callback' -
i'm relatively new node.js, wondering how make asynchronous code more reliable. focusing on code uses 'async' (no promises yet, due legacy reasons).
one of reliability concerns failing invoke callbacks. e.g.
async.series([ function(callback){ if(..) console.log("invalid input, try again"); // bug: no callback! else callback(null, 'ok'); }, function(callback){ ... } ], function(err,result){ handleerrororresult(err,result);} // might not reached );
this code may never complete (never reach 'handleerrororresult') , won't know went wrong. since pit easy fall into, wonder whether there ready-made library solutions it? ideas welcome, 1 direction might timeouts: invoke error handler if whole thing isn't completed within, say, 5 minutes.
thanks much
make own wrapper implements timeout.
var myasync = { series: function (callbacks, timeout, done) { var timeoutid = settimeout(function () { done("maximum time exceeded method!"); }, timeout); async.series(callbacks, function () { cleartimeout(timeoutid); done.apply(this, arguments); }); } }
now can use like:
myasync.series(functions, functions.length * 500, callback);
Comments
Post a Comment