You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1021 B
42 lines
1021 B
4 years ago
|
'use strict';
|
||
|
|
||
|
Object.defineProperty(exports, "__esModule", {
|
||
|
value: true
|
||
|
});
|
||
|
exports.hasNextTick = exports.hasSetImmediate = undefined;
|
||
|
exports.fallback = fallback;
|
||
|
exports.wrap = wrap;
|
||
|
|
||
|
var _slice = require('./slice');
|
||
|
|
||
|
var _slice2 = _interopRequireDefault(_slice);
|
||
|
|
||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||
|
|
||
|
var hasSetImmediate = exports.hasSetImmediate = typeof setImmediate === 'function' && setImmediate;
|
||
|
var hasNextTick = exports.hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function';
|
||
|
|
||
|
function fallback(fn) {
|
||
|
setTimeout(fn, 0);
|
||
|
}
|
||
|
|
||
|
function wrap(defer) {
|
||
|
return function (fn /*, ...args*/) {
|
||
|
var args = (0, _slice2.default)(arguments, 1);
|
||
|
defer(function () {
|
||
|
fn.apply(null, args);
|
||
|
});
|
||
|
};
|
||
|
}
|
||
|
|
||
|
var _defer;
|
||
|
|
||
|
if (hasSetImmediate) {
|
||
|
_defer = setImmediate;
|
||
|
} else if (hasNextTick) {
|
||
|
_defer = process.nextTick;
|
||
|
} else {
|
||
|
_defer = fallback;
|
||
|
}
|
||
|
|
||
|
exports.default = wrap(_defer);
|