diff --git a/lib/step.js b/lib/step.js index b524a6a..dc83e47 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,20 @@ Step.fn = function StepFn() { } } +// nextTick with browser fallback +if (typeof process === 'undefined' || !(process.nextTick)) { + if (typeof setImmediate == 'function') { + Step.nextTick = function(fn){ + setImmediate(fn) + }; + } else { + Step.nextTick = function (fn) { + setTimeout(fn, 0); + }; + } +} else { + Step.nextTick = process.nextTick; +} // Hook into commonJS module systems if (typeof module !== 'undefined' && "exports" in module) {