dashp
Version:
Utilities for monadic promises.
30 lines (23 loc) • 650 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _curry = require("./internal/curry");
var _default = (0, _curry.curry2)("delay", (ms, value) => {
let cancel; // eslint-disable-next-line promise/avoid-new
const thunk = new Promise((resolve, reject) => {
let timeOut = setTimeout(() => resolve(value), ms);
cancel = () => {
if (timeOut) {
clearTimeout(timeOut);
timeOut = null;
}
reject(new Error("Promise canceled"));
};
});
thunk.cancel = cancel;
return thunk;
});
exports.default = _default;
//# sourceMappingURL=delay.js.map