UNPKG

dev-classes

Version:

<h3 align="center">SocketApi</h3> ### !!! Пакет пепеехал в lib-socket-api !!!

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