From 5bc1a5163d07e23d968c15ba37ff777a9d2fd5a5 Mon Sep 17 00:00:00 2001 From: prabirshrestha Date: Sat, 26 Jan 2013 01:02:16 -0500 Subject: [PATCH 1/3] nextTick with browser fallback --- lib/step.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/step.js b/lib/step.js index b524a6a..c775daa 100755 --- a/lib/step.js +++ b/lib/step.js @@ -99,7 +99,7 @@ function Step() { localCallback(error, result); } } - process.nextTick(check); // Ensures that check is called at least once + Step.nextTick(check); // Ensures that check is called at least once // Generates a callback for the group return function () { @@ -145,6 +145,14 @@ Step.fn = function StepFn() { } } +// nextTick with browser fallback +if (typeof process === 'undefined' || !(process.nextTick)) { + Step.nextTick = function (fn) { + setTimeout(fn, 0); + }; +} else { + Step.nextTick = process.nextTick; +} // Hook into commonJS module systems if (typeof module !== 'undefined' && "exports" in module) { From a3f2e648c960725239920b2a8fbdad24c32c467a Mon Sep 17 00:00:00 2001 From: shebson Date: Wed, 3 Jul 2013 10:17:01 -0700 Subject: [PATCH 2/3] Adds setImmediate fallback if process.nextTick isn't available --- lib/step.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/step.js b/lib/step.js index c775daa..6700b56 100755 --- a/lib/step.js +++ b/lib/step.js @@ -147,9 +147,15 @@ Step.fn = function StepFn() { // nextTick with browser fallback if (typeof process === 'undefined' || !(process.nextTick)) { - Step.nextTick = function (fn) { - setTimeout(fn, 0); - }; + if (typeof setImmediate == 'function') { + Step.nextTick = function(fn){ + setImmediate(fn) + }; + }else{ + Step.nextTick = function (fn) { + setTimeout(fn, 0); + }; + } } else { Step.nextTick = process.nextTick; } From 7ab85f0c3769d3ba7f8f65d7863e57d18f5f8b5f Mon Sep 17 00:00:00 2001 From: shebson Date: Wed, 3 Jul 2013 12:19:59 -0700 Subject: [PATCH 3/3] Space before and after else (thanks prabirshrestha) --- lib/step.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/step.js b/lib/step.js index 6700b56..dc83e47 100755 --- a/lib/step.js +++ b/lib/step.js @@ -151,7 +151,7 @@ if (typeof process === 'undefined' || !(process.nextTick)) { Step.nextTick = function(fn){ setImmediate(fn) }; - }else{ + } else { Step.nextTick = function (fn) { setTimeout(fn, 0); };