Opal-Estate-Pro/node_modules/timers-ext/delay.js
2019-09-13 11:27:52 +07:00

22 lines
506 B
JavaScript
Executable File

"use strict";
var callable = require("es5-ext/object/valid-callable")
, nextTick = require("next-tick")
, validTimeout = require("./valid-timeout");
var apply = Function.prototype.apply;
module.exports = function (fn/*, timeout*/) {
var delay, timeout = arguments[1];
callable(fn);
if (timeout === undefined) {
delay = nextTick;
} else {
timeout = validTimeout(timeout);
delay = setTimeout;
}
return function () {
return delay(apply.bind(fn, this, arguments), timeout);
};
};