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

22 lines
588 B
JavaScript
Executable File

"use strict";
var isValue = require("es5-ext/object/is-value")
, isPromise = require("es5-ext/object/is-promise")
, nextTick = require("next-tick")
, ensureTimeout = require("../valid-timeout");
module.exports = function (/* timeout */) {
var Constructor = isPromise(this) ? this.constructor : Promise;
var timeout = arguments[0];
if (isValue(timeout)) timeout = ensureTimeout(timeout);
return new Constructor(function (resolve) {
if (isValue(timeout)) {
setTimeout(function () {
resolve();
}, timeout);
} else {
nextTick(resolve);
}
});
};