| 1 |
"use strict"; |
| 2 |
|
| 3 |
var isValue = require("es5-ext/object/is-value") |
| 4 |
, isPromise = require("es5-ext/object/is-promise") |
| 5 |
, nextTick = require("next-tick") |
| 6 |
, ensureTimeout = require("../valid-timeout"); |
| 7 |
|
| 8 |
module.exports = function (/* timeout */) { |
| 9 |
var Constructor = isPromise(this) ? this.constructor : Promise; |
| 10 |
var timeout = arguments[0]; |
| 11 |
if (isValue(timeout)) timeout = ensureTimeout(timeout); |
| 12 |
return new Constructor(function (resolve) { |
| 13 |
if (isValue(timeout)) { |
| 14 |
setTimeout(function () { resolve(); }, timeout); |
| 15 |
} else { |
| 16 |
nextTick(resolve); |
| 17 |
} |
| 18 |
}); |
| 19 |
}; |