Opal-Estate-Pro/node_modules/timers-ext/test/promise/sleep.js

35 lines
626 B
JavaScript
Raw Normal View History

2019-09-13 06:27:52 +02:00
"use strict";
var delay = require("../../delay");
module.exports = function (t, a) {
if (typeof Promise !== "function") return null;
return {
Tick: function (d) {
var isInvoked = false;
t().then(function (result) {
isInvoked = true;
delay(function () {
a(result, undefined);
d();
})();
}, delay(d));
a(isInvoked, false);
},
Timeout: function (d) {
var isInvoked = false;
t(100).then(
delay(function (result) {
isInvoked = true;
a(result, undefined);
d();
}),
delay(d)
);
setTimeout(function () {
a(isInvoked, false);
}, 50);
}
};
};