Skip to content

Commit

Permalink
Extract nextTick to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
mroderick committed Jan 8, 2018
1 parent 5fa0e66 commit 8c1e221
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
15 changes: 1 addition & 14 deletions lib/sinon/behavior.js
Expand Up @@ -2,27 +2,14 @@

var extend = require("./util/core/extend");
var functionName = require("./util/core/function-name");
var nextTick = require("./util/core/next-tick");
var valueToString = require("./util/core/value-to-string");

var slice = Array.prototype.slice;
var join = Array.prototype.join;
var useLeftMostCallback = -1;
var useRightMostCallback = -2;

var nextTick = (function () {
if (typeof process === "object" && typeof process.nextTick === "function") {
return process.nextTick;
}

if (typeof setImmediate === "function") {
return setImmediate;
}

return function (callback) {
setTimeout(callback, 0);
};
})();

function getCallback(behavior, args) {
var callArgAt = behavior.callArgAt;

Expand Down
20 changes: 20 additions & 0 deletions lib/sinon/util/core/next-tick.js
@@ -0,0 +1,20 @@
"use strict";

var hasNextTick = typeof process === "object" && typeof process.nextTick === "function";
var hasSetImmediate = typeof setImmediate === "function";

function nextTick(callback) {
setTimeout(callback, 0);
}

if (hasNextTick) {
module.exports = process.nextTick;
}

if (!hasNextTick && hasSetImmediate) {
module.exports = setImmediate;
}

if (!hasNextTick && !hasSetImmediate) {
module.exports = nextTick;
}

0 comments on commit 8c1e221

Please sign in to comment.