From 4b8de42cf467afcb11d22a6f8d56af57b3ebf3fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mustafa=20Dokumac=C4=B1?= Date: Mon, 4 May 2015 14:29:54 +0300 Subject: [PATCH] callbackNextTick method added to API Sometimes an async function needs tor return a sync result. For the sake of consistency of async flow; we need to call the callback function wrapped in a nextTick block. This new method simplifys this effort. Example: ```js function asyncFn (other_arguments, callback) { if (cached_result) { return async.callbackNextTick(callback, cached_result); } some_async_call(some_arguments, callback); } ``` --- lib/async.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/async.js b/lib/async.js index 394c41cad..fc792c0a2 100644 --- a/lib/async.js +++ b/lib/async.js @@ -656,6 +656,13 @@ }; }; + async.callbackNextTick = function (fn) { + var args = Array.prototype.slice.call(arguments, 1); + return async.nextTick(function () { + return fn.apply(null, args); + }); + }; + var _concat = function (eachfn, arr, fn, callback) { var r = []; eachfn(arr, function (x, cb) {