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 Apr 30, 2018
1 parent ad673fe commit 738638d
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 738638d

Please sign in to comment.