UNPKG

dev-classes

Version:
70 lines (69 loc) 2.42 kB
var i = Object.defineProperty; var o = (u, e, t) => e in u ? i(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t; var I = (u, e, t) => (o(u, typeof e != "symbol" ? e + "" : e, t), t); class h { constructor() { I(this, "defaultProps", { interval: 5e3 }); I(this, "startActionEvery", (e, t = this.defaultProps) => { const a = (s) => { t != null && t.watchIdInterval && (t == null || t.watchIdInterval(s)); }, v = (s) => { t != null && t.controlAction && (t == null || t.controlAction(s)); }; return new Promise((s, l) => { let n = 0, m = 0; const r = { isActive: !0 }, A = setInterval( () => { if (n += t.interval, m += 1, t != null && t.cutoffTime && n > t.cutoffTime || t != null && t.countAction && (t == null ? void 0 : t.countAction) < m) { r.isActive = !1, clearInterval(A), a(null), l({ status: !1, msg: Error("Время загрузки истекло") }); return; } e() && (r.isActive = !1, clearInterval(A), a(null), s({ status: !0, msg: "cb вернул true" })); }, t.interval < 200 ? 200 : t.interval ); a(A), v({ getIsActiveEvent: () => r.isActive, stop: (p) => { const d = "Ручное завершение startActionEvery"; r.isActive = !1, clearInterval(A), a(null), p ? s({ status: p, msg: d + ": (true)" }) : l({ status: p, msg: d + ": (false)" }); } }); }); }); I(this, "oneOf", (e, t, { second: a }) => { let v = 1; e().then(() => { v === 1 && (v = 0); }); let s = setInterval(() => { v === 1 && t(), clearInterval(s); }, a * 1e3); }); I(this, "oneOfPromise", (e, t, { second: a }) => new Promise((v, s) => { let l = 1, n = { status: !1, msg: "" }; e().then((r) => { l === 1 && (l = 0, v(r)); }).catch((r) => { l === 1 && (l = 0, n.msg = r, s(r)); }); let m = setInterval(() => { if (l === 1) { if (l = 0, typeof t == "function") { s({ status: !1, msg: "", ...t(n) }); return; } s({ status: !1, msg: "oneOfPromise reject" }); } clearInterval(m); }, a * 1e3); })); } } export { h as DelaysPromise };