UNPKG

@creejs/commons-retrier

Version:
1 lines 151 kB
{"version":3,"file":"index-dev.cjs","sources":["../../../lang/dist/esm/index-min.js","../../lib/constants.js","../../lib/policy.js","../../../events/dist/esm/index-min.js","../../lib/event.js","../../lib/policy/fixed-interval-policy.js","../../lib/policy/fixed-increase-policy.js","../../lib/policy/factor-increase-policy.js","../../lib/policy/shuttle-policy.js","../../lib/policy/fixed-backoff.js","../../lib/policy/exponential-backoff.js","../../lib/policy/linear-backoff.js","../../lib/task.js","../../lib/alway-task.js","../../lib/forever-task.js","../../lib/retrier.js","../../lib/retrier-factory.js","../../lib/index.js"],"sourcesContent":["const t={NOT_FOUND:404,NOT_SUPPORTED:505,NOT_IMPL:501};class r extends Error{static get Code(){return t}static isErrorLike(t){return null!=t&&(\"_\"===t._type&&\"number\"==typeof t.code)}static timeout(t,e){return new r(`Timeout ${e}ms: ${t}`,504)}static preconditionFailed(t){return new r(`Not Matched: ${t}`,412)}static notFound(t){return new r(`Not Found: ${t}`,404)}static notImpled(){return new r(\"Not Impled Yet\",501)}static notSupported(t){return new r(\"Not Supported:\"+t,505)}static isNotSupported(t){return 505===t?.code}constructor(t,r){super(t),this._type=\"_\",this.code=r}}class e extends Error{static isAggregatedErrorLike(t){return t&&Array.isArray(t.errors)}static isAggregatedError(t){return t instanceof e}constructor(t,r){super(t),this.errors=r??[]}addError(t){this.errors.push(t)}removeError(t){const r=this.errors.indexOf(t);return-1!==r&&(this.errors.splice(r,1),!0)}}var n={get:function(t,r,e){if(null==t)return e;if(\"string\"!=typeof r)throw new Error('\"path\" must be a string');const n=r.split(\".\");let o=t;for(const t of n){if(void 0===o[t])return e;o=o[t]}return o},constructorName:o,defaults:function(t,...r){if(null==t)throw new TypeError('\"target\" Should Not Nil');for(const e of r)if(null!=e)for(const r in e)void 0===t[r]&&(t[r]=e[r]);return t},extend:i,extends:i,equals:function(t,r){if(t===r)return!0;if(\"function\"==typeof t?.equals)return t.equals(r);if(\"function\"==typeof r?.equals)return r.equals(t);return!1},isBrowser:s,isNode:function(){return!s()},cloneToPlainObject:function(t){if(null==t)return t;if(\"object\"!=typeof t)throw new Error(\"Only Object allowed to clone\");return{...t}},deepCloneToPlainObject:function(t){if(null==t)return t;if(\"object\"!=typeof t)throw new Error(\"Only Object allowed to clone\");return JSON.parse(JSON.stringify(t))}};function o(t){return t?.constructor?.name}function i(t,...r){if(null==t)throw new TypeError('\"target\" must not be null or undefined');for(const e of r)if(null!=e)for(const r in e)t[r]=e[r];return t}function s(){return\"undefined\"!=typeof window&&\"undefined\"!=typeof document}var u={isArray:f,isBoolean:a,isBuffer:function(t){return null!=t&&Buffer.isBuffer(t)},isFunction:c,isInstance:l,isIterable:y,isDate:function(t){return null!=t&&t instanceof Date},isError:function(t){return null!=t&&t instanceof Error},isMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Map},isWeakMap:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakMap},isNumber:b,isPositive:h,isNegative:w,isNotNegative:g,isNil:p,isNullOrUndefined:function(t){return null==t},isNull:d,isUndefined:m,isPlainObject:E,isObject:A,isPromise:N,isRegExp:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===RegExp},isSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===Set},isWeakSet:function(t){return null!=t&&\"object\"==typeof t&&t.constructor===WeakSet},isStream:function(t){return null!=t&&\"function\"==typeof t.pipe},isString:$,isSymbol:v,isPrimitive:function(t){return null!==t&&(\"string\"==typeof t||\"number\"==typeof t||\"boolean\"==typeof t)},isInt8Array:P,isUint8Array:j,isUint8ClampedArray:S,isInt16Array:x,isUint16Array:I,isInt32Array:U,isUint32Array:T,isFloat32Array:B,isFloat64Array:k,isBigInt64Array:L,isBigUint64Array:F,isTypedArray:O,isArrayBuffer:C};function f(t){return Array.isArray(t)}function a(t){return\"boolean\"==typeof t}function c(t){return\"function\"==typeof t}function l(t){return null!=t&&\"object\"==typeof t&&!E(t)}function y(t){return null!=t&&\"function\"==typeof t[Symbol.iterator]}function p(t){return null==t}function h(t){return!!b(t)&&t>0}function g(t){return!!b(t)&&t>=0}function w(t){return!!b(t)&&t<0}function d(t){return null===t}function m(t){return void 0===t}function b(t){return null!=t&&\"number\"==typeof t}function A(t){return null!=t&&\"object\"==typeof t}function E(t){return null!==t&&\"object\"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function N(t){return null!=t&&\"function\"==typeof t.then}function $(t){return null!=t&&\"string\"==typeof t}function v(t){return null!=t&&\"symbol\"==typeof t}function O(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function P(t){return t instanceof Int8Array}function j(t){return t instanceof Uint8Array}function S(t){return t instanceof Uint8ClampedArray}function x(t){return t instanceof Int16Array}function I(t){return t instanceof Uint16Array}function U(t){return t instanceof Int32Array}function T(t){return t instanceof Uint32Array}function B(t){return t instanceof Float32Array}function k(t){return t instanceof Float64Array}function L(t){return t instanceof BigInt64Array}function F(t){return t instanceof BigUint64Array}function C(t){return t instanceof ArrayBuffer}var M={assertNumber:_,assertPositive:R,assertNegative:function(t,r){if(!w(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Negative: ${t}`)},assertNotNegative:J,assertBoolean:function(t,r){if(!a(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Boolean: type=${typeof t} value=${tt(t)}`)},assertObject:W,assertPlainObject:function(t,r){if(!E(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not PlainObject: type=${typeof t} value=${tt(t)}`)},assertSymbol:function(t,r){if(!v(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Symbol: type=${typeof t} value=${tt(t)}`)},assertFunction:H,assertInstance:function(t,r){if(!l(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Class Instance: type=${typeof t} value=${tt(t)}`)},assertPromise:V,assertNil:function(t,r){if(!p(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Neither Null nor Undefined: type=${typeof t} value=${tt(t)}`)},assertNotNil:z,assertNull:function(t,r){if(!d(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Null: type=${typeof t} value=${tt(t)}`)},assertNotNull:function(t,r){if(d(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Should Not Null\")},assertUndefined:function(t,r){if(!m(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Undefined: type=${typeof t} value=${tt(t)}`)},assertString:q,assertArray:D,assertStringOrSymbol:function(t,r){if(!$(t)&&!v(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not String or Symbol: type=${typeof t} value=${tt(t)}`)},assertInt8Array:function(t,r){if(P(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Int8Array\")},assertUint8Array:function(t,r){if(j(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Uint8Array\")},assertUint8ClampedArray:function(t,r){if(S(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Uint8ClampedArray\")},assertInt16Array:function(t,r){if(x(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Int16Array\")},assertUint16Array:function(t,r){if(I(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Uint16Array\")},assertInt32Array:function(t,r){if(U(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Int32Array\")},assertUint32Array:function(t,r){if(T(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Uint32Array\")},assertFloat32Array:function(t,r){if(B(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Float32Array\")},assertFloat64Array:function(t,r){if(k(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Float64Array\")},assertBigInt64Array:function(t,r){if(L(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not BigInt64Array\")},assertBigUint64Array:function(t,r){if(F(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not BigUint64Array\")},assertTypedArray:function(t,r){if(O(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not TypedArray\")},assertArrayBuffer:G,assertIterable:function(t,r){if(!y(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not Iterable\")}};function D(t,r){if(!Array.isArray(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Array: type=${typeof t} value=${tt(t)}`)}function q(t,r){if(!$(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not String: type=${typeof t} value=${tt(t)}`)}function _(t,r){if(!b(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Number: type=${typeof t} value=${tt(t)}`)}function R(t,r){if(!h(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Positive: ${t}`)}function J(t,r){if(!g(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not \"0 or Positive\": ${t}`)}function W(t,r){if(!A(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Object: type=${typeof t} value=${tt(t)}`)}function H(t,r){if(!c(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Function: type=${typeof t} value=${tt(t)}`)}function V(t,r){if(!N(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Not Promise: type=${typeof t} value=${tt(t)}`)}function z(t,r){if(p(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Should Not Nil\")}function G(t,r){if(!C(t))throw new Error((r?'\"'+r+'\" ':\"\")+\"Not ArrayBuffer\")}var K={isEmpty:Y,assertNotEmpty:Q,isBlank:X,assertNotBlank:function(t,r){if(X(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}Is Blank: ${t}`)},capitalize:function(t){if(q(t),0===t.length)return t;const r=t.charAt(0),e=r.toUpperCase();return r===e?t:e+t.slice(1)},decapitalize:function(t){if(q(t),0===t.length)return t;const r=t.charAt(0),e=r.toLowerCase();return r===e?t:e+t.slice(1)},splitWithFixedLength:function(t,r,e=\" \"){if(q(t),_(r),q(e),0===t.length)return[];if(r<=0)throw new Error(\"length muse >=0\");if(t.length<r)return[t.padEnd(r,e)];const n=[];for(let o=0;o<t.length;o+=r){const i=t.substring(o,o+r);n.push(i.padEnd(r,e))}return n},split:function(t,...r){q(t);if(0===t.length)return[];const e=[...r];0===r.length&&r.push(\",\");const n=Z(t,...e);if(0===n.length)return[];const o=[];let i=\"\",s=0;for(const{marker:r,index:e}of n)i=t.substring(s,e),o.push(i),s=e+r.length;return i=t.substring(s),o.push(i),o},findMarkerPositions:function(t,...r){if(q(t),0===r.length)throw new Error(\"At least one marker must be provided\");const e=[];for(const n of new Set(r)){if(Y(n))continue;q(n);let r=t.indexOf(n);for(;-1!==r;)e.push({marker:n,index:r}),r=t.indexOf(n,r+n.length)}return e.sort((t,r)=>t.index-r.index),e},findMarkerPositionsRegex:Z,substringBefore:function(t,r){if(q(t),q(r),0===t.length||0===r.length)return;const e=t.indexOf(r);if(-1===e)return;return t.substring(0,e)},substringBeforeLast:function(t,r){if(q(t),q(r),0===t.length||0===r.length)return;const e=t.lastIndexOf(r);if(-1===e)return;return t.substring(0,e)},substringAfter:function(t,r){if(q(t),q(r),0===t.length||0===r.length)return;const e=t.indexOf(r);if(-1===e)return;return t.substring(e+r.length)},substringAfterLast:function(t,r){if(q(t),q(r),0===t.length||0===r.length)return;const e=t.lastIndexOf(r);if(-1===e)return;return t.substring(e+r.length)},substringBetween:function(t,r,e){Q(t),Q(r),Q(e);const n=t.indexOf(r);if(-1===n)return;const o=t.indexOf(e,n+r.length);if(-1===o)return;return t.substring(n+r.length,o)},substringBetweenGreedy:function(t,r,e){Q(t),Q(r),Q(e);const n=t.indexOf(r);if(-1===n)return;const o=t.lastIndexOf(e);if(-1===o||o<=n)return;return t.substring(n+r.length,o)},substringsBetween:function(t,r,e){Q(t),Q(r),Q(e);const n=[];let o=0;for(;;){const i=t.indexOf(r,o);if(-1===i)break;const s=t.indexOf(e,i+r.length);if(-1===s)break;n.push(t.substring(i+r.length,s)),o=s+e.length}return n},safeToString:tt};function Y(t){return null==t||(q(t),0===t.length)}function Q(t,r){if(Y(t))throw new Error(`${r?'\"'+r+'\" ':\"\"}IsEmpty String: ${t}`)}function X(t){return null==t||(q(t),0===t.trim().length)}function Z(t,...r){if(q(t),0===r.length)throw new Error(\"At least one marker must be provided\");const e=[...new Set(r.filter(t=>null!=t))].map(t=>(q(t),t.replace(/[.*+?^${}()|[\\]\\\\]/g,\"\\\\$&\"))),n=new RegExp(e.map(t=>`(${t})`).join(\"|\"),\"g\"),o=[];let i=null;for(;null!==(i=n.exec(t));){for(let t=1;t<i.length;t++)if(i[t]){o.push({marker:r[t-1],index:i.index});break}0===i[0].length&&n.lastIndex++}return o}function tt(t){if(null===t)return\"null\";if(void 0===t)return\"undefined\";const r=typeof t;if(\"string\"===r)return t;if(\"symbol\"===r)return`Symbol(${t.description})`;if(\"function\"===r)return`Function ${t.name}(){}`;if(t instanceof String)return t.toString();if(Number.isNaN(t))return\"NaN\";if(t===1/0)return\"Infinity\";if(t===-1/0)return\"-Infinity\";if(t instanceof Error)return`${t.constructor.name}: ${t.message}`;if(t instanceof Promise)return\"Promise\";if(t instanceof Set)return`Set: ${tt(Array.from(t))}`;if(t instanceof Map)return`Map: ${tt(Array.from(t.entries()))}`;if(t instanceof RegExp)return t.toString();if(Array.isArray(t))return`[${t.map(tt).join(\", \")}]`;let e;try{e=JSON.stringify(t)}catch(r){e=t.toString()}return e}var rt={quiet:function(t,r){H(t);try{const e=t();return N(e)?e.catch(t=>{r&&r.isErrorEnabled()&&r.error(\"quiet() with async error:\",t)}):e}catch(t){r&&r.isErrorEnabled()&&r.error(\"quiet() with sync error:\",t)}},quietKeepError:function(t,r){H(t),D(r);try{const e=t();return N(e)?e.catch(t=>r.push(t)):e}catch(t){r.push(t)}}},et={any:function(t){if(D(t),0===t.length)throw new Error(\"Empty Tasks\");const r=nt(),n=[];for(let o=0;o<t.length;o++){const i=t[o];let s;if(u.isPromise(i))s=i;else{if(!u.isFunction(i)){n.push(new Error(`Invalid Task at index ${o}/${t.length-1}: ${i}`));continue}s=it(i)}s.then(t=>{r.resolve(t)}).catch(o=>{n.push(o),n.length>=t.length&&r.reject(new e(\"All Tasks Failed\",n))})}n.length===t.length&&r.reject(new e(\"All Tasks Failed\",n));return r.promise},defer:nt,delay:function(t,r){u.isNumber(t)?(r=t,t=Promise.resolve()):null==t&&null==r&&(r=1,t=Promise.resolve());null!=t&&V(t),_(r=r??1e3);const e=nt(),n=Date.now();return t.then((...t)=>{const o=Date.now()-n;o<r?setTimeout(()=>e.resolve(...t),r-o):e.resolve(...t)}).catch(t=>{const o=Date.now()-n;o<r?setTimeout(()=>e.reject(t),r-o):e.reject(t)}),e.promise},timeout:function(t,r,e){V(t),_(r=r??1);const n=nt(r,e),o=Date.now();return t.then((...t)=>{Date.now()-o<=r?n.resolve(...t):n.reject(new Error(e??`Promise Timeout: ${r}ms`))}).catch(t=>{!n.resolved&&!n.rejected&&n.reject(t)}),n.promise},allSettled:ot,returnValuePromised:it,series:async function(t){D(t);const r=[];for(const e of t)if(H(e),u.isFunction(e))r.push(await it(e));else{if(!u.isPromise(e))throw new Error(`Invalid Task: ${e}`);r.push(await e)}return r},seriesAllSettled:async function(t){D(t);const r=[];for(const e of t){H(e);try{r.push({ok:!0,result:await e()})}catch(t){r.push({ok:!1,result:t})}}return r},parallel:async function(t,r=5){if(D(t),_(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>H(t));const e=[];if(t.length<=r){const r=await Promise.all(t.map(t=>it(t)));return e.push(...r),e}const n=[];for(const o of t)if(H(o),n.push(o),n.length>=r){const t=await Promise.all(n.map(t=>it(t)));e.push(...t),n.length=0}if(n.length>0&&n.length<r){const t=await Promise.all(n.map(t=>it(t)));e.push(...t)}return e},parallelAny:async function(t,r=5,n){if(D(t,\"tasks\"),_(r),0===t.length)throw new Error(\"Empty Tasks\");if(r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);const o=[];let i=0,s=0;const f=nt();function a(){if(i>=t.length)return;if(s>r)return;const c=t[i++];let l;s++,l=u.isPromise(c)?c:u.isFunction(c)?it(c):Promise.reject(new TypeError(`Invalid task: ${typeof c}, Only Promise or Function allowed`)),l.then(t=>{s--,f.resolve(t)}).catch(r=>{o.push(r),o.length>=t.length&&f.pending?f.reject(new e(n??\"All Tasks Failed\",o)):(s--,a())})}const c=Math.min(t.length,r);for(let t=0;t<c;t++)a();return f.promise},parallelAllSettled:async function(t,r=5){if(D(t),_(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>H(t));const e=[];if(t.length<=r){const r=await ot(t.map(t=>it(t)));return e.push(...r),e}const n=[];for(const o of t)if(n.push(o),n.length>=r){const t=await ot(n.map(t=>it(t)));e.push(...t),n.length=0}if(n.length>0&&n.length<r){const t=await ot(n.map(t=>it(t)));e.push(...t)}return e},wait:function(t){J(t);const r={};let e;return r.timerHandler=e=setTimeout(()=>{clearTimeout(e),r._resolve()},t),r.promise=new Promise((t,n)=>{r._resolve=r=>{null!=e&&clearTimeout(e),t(r)}}),r.wakeup=()=>{r._resolve()},r}};function nt(t=-1,r){_(t);const e={};let n;return e.pending=!0,e.canceled=!1,e.rejected=!1,e.resolved=!1,t>=0&&(e.timerCleared=!1,e.timerHandler=n=setTimeout(()=>{clearTimeout(n),e.timerCleared=!0,e.reject(new Error(r??`Promise Timeout: ${t}ms`))},t)),e.promise=new Promise((t,r)=>{e.resolve=r=>{e.resolved||e.rejected||e.canceled||(null!=n&&(clearTimeout(n),e.timerCleared=!0),e.pending=!1,e.canceled=!1,e.rejected=!1,e.resolved=!0,t(r))},e.reject=t=>{e.resolved||e.rejected||e.canceled||(null!=n&&(clearTimeout(n),e.timerCleared=!0),e.pending=!1,e.canceled=!1,e.resolved=!1,e.rejected=!0,r(t))}}),e.cancel=e.promise.cancel=t=>{e.resolved||e.rejected||e.canceled||(null!=n&&(clearTimeout(n),e.timerCleared=!0),e.reject(t??new Error(\"Cancelled\")),e.canceled=e.promise.canceled=!0)},e}async function ot(t){D(t);const r=await Promise.allSettled(t),e=[];for(const t of r)\"fulfilled\"===t.status&&e.push({ok:!0,result:t.value}),\"rejected\"===t.status&&e.push({ok:!1,result:t.reason});return e}function it(t){try{const r=t();return u.isPromise(r)?r:Promise.resolve(r)}catch(t){return Promise.reject(t)}}const{isPlainObject:st}=u;var ut={proxy:ft,newProxyInstance:function(t,r,e,n=!0){const o=ft(t,e,n);return Reflect.construct(o,r??[])}};function ft(t,r,e=!0){if(\"function\"!=typeof t)throw new TypeError(`Not Class: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=r){if(!st(r))throw new TypeError(`Not PropertyHandler: type=${typeof r}, value=${JSON.stringify(r)}`);const{get:t,set:e}=r;if(null!=t&&\"function\"!=typeof t)throw new TypeError(`Not PropertyHandler.get: type=${typeof t}, value=${JSON.stringify(t)}`);if(null!=e&&\"function\"!=typeof e)throw new TypeError(`Not PropertyHandler.set: type=${typeof e}, value=${JSON.stringify(e)}`)}const n={construct(t,n,o){const i=Reflect.construct(t,n);return new Proxy(e?Object.preventExtensions(i):i,r??{})}};return new Proxy(t,n)}var at={proxy:function(t,r,e=!0){if(p(t)||!A(t)||f(t))throw new TypeError(`Not Object: type=${typeof t}, value=${JSON.stringify(t)}`);return new Proxy(e?Object.preventExtensions(t):t,r??{})}};function ct(t){W(t,\"obj\");const r=new Set;let e=t;for(;e&&e!==Object.prototype;){const n=Object.getOwnPropertyNames(e);for(const e of n)\"constructor\"!==e&&\"function\"==typeof t[e]&&r.add(e);e=Object.getPrototypeOf(e)}return[...new Set(r)]}var lt={getMethodsOfClass:function(t){H(t,\"cls\");const r=new Set;let e=t.prototype;for(;e&&e!==Object.prototype;){const t=Object.getOwnPropertyNames(e);for(const n of t)\"constructor\"!==n&&\"function\"==typeof e[n]&&r.add(n);e=Object.getPrototypeOf(e)}return[...new Set(r)]},getStaticMethodsOfClass:function(t){H(t,\"cls\");const r=new Set;let e=t;for(;e&&e!==Object.getPrototypeOf(Object);){const t=Object.getOwnPropertyNames(e);for(const n of t)\"function\"==typeof e[n]&&r.add(n);e=Object.getPrototypeOf(e)}return[...r]},getMethods:ct,getMethodsOfObject:ct},yt={startsWith:function(t,r){z(t,\"src\"),z(r,\"searching\");return ht(t.subarray(0,r.length),r)},isSameType:pt,equals:ht};function pt(t,r){return z(t,\"src\"),z(r,\"target\"),o(t)===o(r)}function ht(t,r){if(z(t,\"src\"),z(r,\"target\"),!pt(t,r))return!1;if(t.byteLength!==r.byteLength)return!1;const e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=new DataView(r.buffer,r.byteOffset,r.byteLength);for(let r=0;r<t.byteLength;r++)if(e.getUint8(r)!==n.getUint8(r))return!1;return!0}var gt={readString:function(t,r=0,e){if(G(t),J(r),r>=t.byteLength)return;let n=null;null!=e?(R(e),n=r+e>=t.byteLength?new Uint8Array(t,r):new Uint8Array(t,r,e)):n=new Uint8Array(t,r);return wt.decode(n)},writeString:function(t,r,e=0){G(t,\"buffer\"),q(r,\"str\"),J(e,\"offset\");const n=dt.encode(r),o=n.byteLength;if(e+o>t.byteLength)throw new Error(`offset + str.byteLength > buffer.byteLength:${e+o} > ${t.byteLength}`);new Uint8Array(t,e,n.byteLength).set(n)},writeArrayBuffer:function(t,r,e=0,n=0,o){G(t),G(r),_(e),_(n);const i=t.byteLength;if(e<-1*i)e=0;else if(e<0)e+=i;else if(e>=i)throw new Error(`Out of target Bounds: targetOffset(${e}) >= targetLength(${i})`);const s=r.byteLength;if(n<-1*s)n=0;else if(n<0)n+=s;else if(n>=s)throw new Error(`Out of data Bounds: dataOffset(${n}) >= dataArrayBufferLength(${s})`);null!=o&&(R(o,\"dataLength\"),n+o>s&&(o=void 0));const u=new Uint8Array(r,n,o);if(u.byteLength>i-e)throw new Error(`Out of target Bounds: from targetOffset(${e}), No Space to store dataArrayBuffer(${n}, ${o??\"NoLimit\"})`);new Uint8Array(t).set(u,e)}};const wt=new TextDecoder,dt=new TextEncoder;const mt=1e6;var bt={s2ns:1e9,ms2ns:mt,timestamp:function(){if(\"undefined\"!=typeof performance&&\"number\"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return Math.ceil((t+r)/mt)}return Date.now()},timestamp64:At,lapseNano:Et,lapseMillis:Nt,timeoutNano:function(t,r){return Et(t)>r},timeoutMillis:function(t,r){return Nt(t)>r}};function At(){if(\"undefined\"!=typeof performance&&\"number\"==typeof performance.timeOrigin){const t=performance.timeOrigin,r=performance.now();return BigInt((t+r)*mt)}return BigInt(Date.now()*mt)}function Et(t,r){return(r??At())-t}function Nt(t,r){r=r??At();return BigInt(r-t)/BigInt(mt)}var $t={first:function(t,r){return D(t,\"arr\"),t[0]??r},chunk:function(t,r){if(D(t,\"array\"),R(r,\"size\"),t.length<=r)return t;const e=[];let n=0;for(;n<t.length;)e.push(t.slice(n,r+n)),n+=r;return e},last:function(t,r){return D(t,\"arr\"),t[t.length-1]??r},equals:function(t,r,e){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;for(let n=0;n<t.length;n++)if(e){if(0!==e(t[n],r[n]))return!1}else if(t[n]!==r[n])return!1;return!0},equalsIgnoreOrder:function(t,r,e){if(!Array.isArray(t)||!Array.isArray(r))return!1;if(t.length!==r.length)return!1;t.sort(e),r.sort(e);for(let n=0;n<t.length;n++)if(e){if(0!==e(t[n],r[n]))return!1}else if(t[n]!==r[n])return!1;return!0},isSubArray:function(t,r){if(!Array.isArray(t))throw new Error(`\"array\" Not Array: ${t}`);if(!Array.isArray(r))throw new Error(`\"subArray\" Not Array: ${r}`);for(const e of r)if(!t.includes(e))return!1;return!0},notIn:function(t,r){if(!Array.isArray(t))throw new Error(`\"array1\" Not Array: ${t}`);if(!Array.isArray(r))throw new Error(`\"array2\" Not Array: ${r}`);return t.filter(t=>!r.includes(t))}};var vt={take:function(t,r){const e=[];let n;for(let o=0;o<r&&!(n=t.next()).done;o++)e.push(n.value);return e}};var Ot={length:function(t){M.assertIterable(t);const r=t.length??t.size;if(\"number\"==typeof r)return r;let e=0;for(const r of t)e++;return e},take:function(t,r){const e=t[Symbol.iterator](),n=[];let o;for(let t=0;t<r&&!(o=e.next()).done;t++)n.push(o.value);return n}},Pt={_Error:r,AggregatedError:e,LangUtils:n,StringUtils:K,TypeUtils:u,TypeAssert:M,ExecUtils:rt,PromiseUtils:et,Lang:n,Type:u,Exec:rt,ClassProxyUtils:ut,InstanceProxyUtils:at,ReflectUtils:lt,TypedArrayUtils:yt,ArrayBufferUtils:gt,TimeUtils:bt,ArrayUtils:$t,IteratorUtils:vt,IterableUtils:Ot};export{e as AggregatedError,gt as ArrayBufferUtils,$t as ArrayUtils,ut as ClassProxyUtils,rt as Exec,rt as ExecUtils,at as InstanceProxyUtils,Ot as IterableUtils,vt as IteratorUtils,n as Lang,n as LangUtils,et as PromiseUtils,lt as ReflectUtils,K as StringUtils,bt as TimeUtils,u as Type,M as TypeAssert,u as TypeUtils,yt as TypedArrayUtils,r as _Error,Pt as default};\n//# sourceMappingURL=index-min.js.map\n","// module vars\nexport const DefaultMinInterval = 50\nexport const DefaultMaxInterval = 30 * 1000 // 30s\nexport const DefaultMaxRetries = 3\nexport default {\n DefaultMinInterval,\n DefaultMaxInterval,\n DefaultMaxRetries\n}\n","// internal\nimport { TypeAssert, TypeUtils } from '@creejs/commons-lang'\n// owned\nimport { DefaultMaxInterval, DefaultMinInterval } from './constants.js'\n\n// module vars\nconst { assertPositive, assertNotNegative } = TypeAssert\nconst { isNumber } = TypeUtils\n\nexport default class Policy {\n /**\n * Creates a new Policy instance with specified retry bounds.\n */\n constructor () {\n this._min = DefaultMinInterval\n this._max = DefaultMaxInterval\n this._nextInterval = this._min\n this._jitter = 0\n }\n\n get jitter () {\n return this._jitter\n }\n\n set jitter (jitter) {\n assertNotNegative(jitter, 'jitter')\n this._jitter = jitter\n }\n\n /**\n * Copies settings to target policy.\n * 1. range\n * 2. nextInterval value\n * @param {Policy} targetPolicy - The policy to modify.\n */\n copyPolicySettingTo (targetPolicy) {\n targetPolicy.range(this._min, this._max)\n targetPolicy._nextInterval = this._nextInterval\n }\n\n /**\n * Sets a fixed interval retry policy.\n }\n\n /**\n * Sets the minimum and maximum intervals for retries.\n * @param {number} min - Minimum delay in milliseconds (must be positive and less than max)\n * @param {number} max - Maximum delay in milliseconds (must be positive and greater than min)\n * @returns {this} Returns the Retrier instance for chaining\n * @throws {Error} If min is not less than max or if values are not positive\n */\n range (min, max) {\n assertPositive(min, 'min')\n assertPositive(max, 'max')\n if (min >= max) {\n throw new Error('min must < max')\n }\n this._min = min\n if (this._nextInterval < this._min) {\n this._nextInterval = this._min\n }\n this._max = max\n if (this._nextInterval > this._max) {\n this._nextInterval = this._max\n }\n return this\n }\n\n /**\n * Sets the minimum retry delay in milliseconds.\n * 1. will change currentInterval to min\n * @param {number} min - The minimum delay (must be positive and less than max).\n * @returns {this} The retrier instance for chaining.\n * @throws {Error} If min is not positive or is greater than/equal to max.\n */\n min (min) {\n assertPositive(min, 'min')\n if (min >= this._max) {\n throw new Error('min must < max')\n }\n this._min = min\n if (this._nextInterval < this._min) {\n this._nextInterval = this._min\n }\n return this\n }\n\n /**\n * Sets the maximum retry retry delay in milliseconds.\n * @param {number} max - The maximum delay (must be positive and greater than min).\n * @throws {Error} If max is not greater than min.\n * @returns {this} The retrier instance for chaining.\n */\n max (max) {\n assertPositive(max, 'max')\n if (max <= this._min) {\n throw new Error('max must > min')\n }\n this._max = max\n if (this._nextInterval > this._max) {\n this._nextInterval = this._max\n }\n return this\n }\n\n reset () {\n this._nextInterval = this._min\n return this\n }\n\n /**\n * Interval ms of next execution\n * @param {number} retries current retry times\n * @returns {number}\n */\n generate (retries) {\n const rtnVal = this._nextInterval\n this._increase(retries)\n return rtnVal\n }\n\n /**\n * @param {number} retries current retry times\n * @returns {number}\n */\n _increase (retries) {\n const generated = this._next(retries)\n if (!isNumber(generated)) {\n throw new Error('Generated Next Interval Not Number')\n }\n const nextInterval = this._jitter <= 0 ? generated : generated + Math.floor(Math.random() * this._jitter)\n if (nextInterval < this._min) {\n return (this._nextInterval = this._min)\n } else if (nextInterval > this._max) {\n return (this._nextInterval = this._max)\n }\n return (this._nextInterval = nextInterval)\n }\n\n /**\n * subclass should implement this method\n * @param {number} retries current retry times\n * @returns {number} The interval in milliseconds to wait before the next retry attempt.\n * @protected\n */\n _next (retries) {\n throw new Error('Not Impled Yet')\n }\n}\nexport { Policy }\n","var e={isFunction:t,isNil:n};function t(e){return\"function\"==typeof e}function n(e){return null==e}function s(e){return null!=e&&\"string\"==typeof e}var r={assertNumber:function(e,t){if(!function(e){return null!=e&&\"number\"==typeof e}(e))throw new Error(`${t?'\"'+t+'\" ':\"\"}Not Number: type=${typeof e} value=${i(e)}`)},assertFunction:function(e,n){if(!t(e))throw new Error(`${n?'\"'+n+'\" ':\"\"}Not Function: type=${typeof e} value=${i(e)}`)},assertNotNil:function(e,t){if(n(e))throw new Error((t?'\"'+t+'\" ':\"\")+\"Should Not Nil\")},assertString:function(e,t){if(!s(e))throw new Error(`${t?'\"'+t+'\" ':\"\"}Not String: type=${typeof e} value=${i(e)}`)},assertStringOrSymbol:function(e,t){if(!s(e)&&!function(e){return null!=e&&\"symbol\"==typeof e}(e))throw new Error(`${t?'\"'+t+'\" ':\"\"}Not String or Symbol: type=${typeof e} value=${i(e)}`)}};function i(e){if(null===e)return\"null\";if(void 0===e)return\"undefined\";const t=typeof e;if(\"string\"===t)return e;if(\"symbol\"===t)return`Symbol(${e.description})`;if(\"function\"===t)return`Function ${e.name}(){}`;if(e instanceof String)return e.toString();if(Number.isNaN(e))return\"NaN\";if(e===1/0)return\"Infinity\";if(e===-1/0)return\"-Infinity\";if(e instanceof Error)return`${e.constructor.name}: ${e.message}`;if(e instanceof Promise)return\"Promise\";if(e instanceof Set)return`Set: ${i(Array.from(e))}`;if(e instanceof Map)return`Map: ${i(Array.from(e.entries()))}`;if(e instanceof RegExp)return e.toString();if(Array.isArray(e))return`[${e.map(i).join(\", \")}]`;let n;try{n=JSON.stringify(e)}catch(t){n=e.toString()}return n}new TextDecoder,new TextEncoder;const l=\"DOwner$#$\",{assertFunction:a,assertNotNil:o}=r;class c{constructor(e,t,n=!1){o(e,\"event\"),a(t,\"callback\"),this._event=e,this._callback=t,this._isOnce=!!n,this._owner=void 0}set owner(e){this._owner=e}get owner(){return this._owner===l?void 0:this._owner}get event(){return this._event}get isOnce(){return this._isOnce}isSameCallback(e){return this._callback===e}get callback(){return this._callback}invoke(...e){try{return this._callback(...e)}finally{if(this._isOnce)try{this._event._remove(this)}catch(e){console.warn(e)}}}listener(...e){return this.invoke(...e)}}const{isFunction:h,isNil:u}=e,{assertStringOrSymbol:_,assertFunction:f}=r;class m{static get DefaultOwner(){return l}constructor(e){_(e,\"eventName\"),this._name=e,this._callbacks=new Set,this._listeners=[],this._callback2Listeners=new Map,this._listener2Owner=new Map,this._owner2Listeners=new Map}get name(){return this._name}isEmpty(){return 0===this._callbacks.size}rawListeners(){return[...this._listeners]}listenerCount(e){return null==e?this._listeners.length:this._callback2Listeners.get(e)?.size??0}callbacks(){return[...this.rawListeners().map(e=>e.callback)]}emit(...e){if(0===this._listeners.length)return!1;for(const t of[...this._listeners])t.invoke(...e);return!0}emitOwner(e,...t){if(0===this._listeners.length)return!1;const n=this._owner2Listeners.get(e);if(null==n)return!1;for(const e of[...n])e.invoke(...t);return!0}hasListener(e){return!!h(e)&&this._callbacks.has(e)}hasOwner(e){return!u(e)&&this._owner2Listeners.has(e)}addListener(e,t){return this._addListener(e,t,!1,!1)}prependListener(e,t){return this._addListener(e,t,!1,!0)}addOnceListener(e,t){return this._addListener(e,t,!0,!1)}prependOnceListener(e,t){return this._addListener(e,t,!0,!0)}_addListener(e,t,n,s){if(u(e))return!1;f(e),this._callbacks.has(e)||this._callbacks.add(e),t=t??l;const r=new c(this,e,n);r.owner=t,s?this._listeners.unshift(r):this._listeners.push(r),this._listener2Owner.set(r,t);let i=this._callback2Listeners.get(e);null==i&&(i=new Set,this._callback2Listeners.set(e,i)),i.add(r);let a=this._owner2Listeners.get(t);return null==a&&(a=new Set,this._owner2Listeners.set(t,a)),a.add(r),!0}removeListener(e){if(u(e))return!1;if(!this._callbacks.has(e))return!1;this._callbacks.delete(e);const t=this._callback2Listeners.get(e);if(null==t)return!1;this._callback2Listeners.delete(e);for(const e of t){-1!==this._listeners.indexOf(e)&&this._listeners.splice(this._listeners.indexOf(e),1);const t=this._listener2Owner.get(e);if(null==t)continue;this._listener2Owner.delete(e);const n=this._owner2Listeners.get(t);null!=n&&(n.delete(e),0===n.size&&this._owner2Listeners.delete(t))}return!0}_remove(e){const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1);const{callback:n}=e,s=this._callback2Listeners.get(n);null!=s&&(s.delete(e),0===s.size&&(this._callback2Listeners.delete(n),this._callbacks.delete(n)));const r=this._listener2Owner.get(e);if(null==r)return;this._listener2Owner.delete(e);const i=this._owner2Listeners.get(r);null!=i&&(i.delete(e),0===i.size&&this._owner2Listeners.delete(r))}removeAllListeners(e){if(u(e))return this._callbacks.clear(),this._listeners.length=0,this._callback2Listeners.clear(),this._listener2Owner.clear(),this._owner2Listeners.clear(),this;const t=this._owner2Listeners.get(e);if(null==t)return this;this._owner2Listeners.delete(e);for(const e of t){-1!==this._listeners.indexOf(e)&&this._listeners.splice(this._listeners.indexOf(e),1),this._listener2Owner.delete(e);const{callback:t}=e,n=this._callback2Listeners.get(t);null!=n&&(n.delete(e),0===n.size&&(this._callback2Listeners.delete(t),this._callbacks.delete(t)))}return this}}const{isNil:d}=e,{assertString:w,assertFunction:L,assertNumber:v,assertStringOrSymbol:g,assertNotNil:p}=r,b=[\"on\",\"once\",\"addListener\",\"prependListener\",\"prependOnceListener\",\"off\",\"offAll\",\"offOwner\",\"removeAllListeners\",\"removeListener\",\"emit\",\"emitOwner\",\"setMaxListeners\",\"getMaxListeners\",\"hasOwner\",\"listeners\",\"listenerCount\",\"eventNames\",\"rawListeners\"];let O=10;class k{static mixin(e){const t=new k;e.__emitter=t;for(const n of b){const s=t[n];e[n]=s.bind(t)}return e}static get defaultMaxListeners(){return O}static set defaultMaxListeners(e){v(e),O=e??10}constructor(){this._name2Event=new Map,this._maxListeners=O}clean(){this._name2Event.clear()}addListener(e,t,n){return this.on(e,t,n)}prependListener(e,t,n){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependListener(t,n),this}prependOnceListener(e,t,n){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependOnceListener(t,n),this}emit(e,...t){const n=this._name2Event.get(e);return null!=n&&!n.isEmpty()&&(n.emit(...t),!0)}emitOwner(e,t,...n){if(null==t)throw new Error('Missing \"owner\"');const s=this._name2Event.get(e);return null!=s&&!s.isEmpty()&&(s.emitOwner(t,...n),!0)}eventNames(){return[...this._name2Event.keys()]}getMaxListeners(){return this._maxListeners}listenerCount(e,t){g(e,\"eventName\");const n=this._name2Event.get(e);return null==n||n.isEmpty()?0:n.listenerCount(t)}listeners(e){g(e,\"eventName\");const t=this._name2Event.get(e);return null==t||t.isEmpty()?[]:t.callbacks()}off(e,t){const n=this._name2Event.get(e);return null==n?this:(n.removeListener(t),n.isEmpty()?(this._name2Event.delete(e),this):this)}offAll(e,t){g(e,\"eventName\");const n=this._name2Event.get(e);return null==n?this:(n.removeAllListeners(t),n.isEmpty()?(this._name2Event.delete(e),this):this)}offOwner(e){p(e,\"owner\");const t=[...this._name2Event.values()];for(const n of t)n.removeAllListeners(e),n.isEmpty()&&this._name2Event.delete(n.name);return this}on(e,t,n){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).addListener(t,n),this}_checkMaxListeners(e){let t=0;0!==this._maxListeners&&this._maxListeners!==1/0&&(t=this.listenerCount(e))>=this._maxListeners&&console.warn(`maxlistenersexceededwarning: Possible EventEmitter memory leak detected. ${t} ${e} listeners added to [${this}]. Use emitter.setMaxListeners() to increase limit`)}once(e,t,n){w(e),L(t);return this._getOrCreateEvent(e).addOnceListener(t,n),this}rawListeners(e){return this._name2Event.get(e)?.rawListeners()||[]}removeAllListeners(e,t){return this.offAll(e,t)}removeListener(e,t){return this.off(e,t)}setMaxListeners(e){if(v(e),e<0)throw new RangeError(\"maxListeners must >=0\");return this._maxListeners=e,this}_getOrCreateEvent(e){if(this._name2Event.has(e))return this._name2Event.get(e);const t=new m(e);return this._name2Event.set(e,t),t}hasOwner(e){if(d(e))return!1;for(const t of this._name2Event.values())if(t.hasOwner(e))return!0;return!1}}export{k as EventEmitter,k as default};\n//# sourceMappingURL=index-min.js.map\n","export const Start = 'start' // retry started\nexport const Stop = 'stop' // retry stopped\nexport const Retry = 'retry' // one retry began\nexport const Success = 'success' // one task running succeeded\nexport const Failure = 'failure' // one task ran failed\nexport const Timeout = 'timeout' // total timeout\nexport const TaskTimeout = 'task-timeout' // one task timed out\nexport const Completed = 'complete' // all retries completed\nexport const MaxRetries = 'max-retries' // Reach the max retries\n\nexport default {\n Start,\n Retry,\n Success,\n Failure,\n Timeout,\n TaskTimeout,\n Stop,\n Completed,\n MaxRetries\n}\n","// 3rd\n// internal\nimport { TypeAssert } from '@creejs/commons-lang'\n// owned\nimport Policy from '../policy.js'\n// module vars\nconst { assertPositive } = TypeAssert\nexport default class FixedIntervalPolicy extends Policy {\n /**\n * Creates a fixed interval retry policy with the specified interval.\n * @param {number} interval - The fixed interval (in milliseconds) between retry attempts.\n */\n constructor (interval) {\n super()\n this.interval = interval\n }\n\n /**\n * @param {number} interval - The fixed interval (in milliseconds) between retry attempts.\n */\n set interval (interval) {\n assertPositive(interval, 'interval')\n this._interval = interval\n this._nextInterval = interval\n this._min = interval\n this._max = interval\n }\n\n /**\n * @returns {number}\n */\n get interval () {\n // @ts-ignore not possible be undefined\n return this._interval\n }\n\n /**\n * Interval ms of next execution\n * @param {number} retries\n * @returns {number}\n * @throws {Error} Always throws \"Not Implemented Yet\" error.\n */\n _next (retries) {\n return this.interval\n }\n}\n\nexport { FixedIntervalPolicy as FixedIntervalPolicyType }\n","// 3rd\n// internal\nimport { TypeAssert } from '@creejs/commons-lang'\n// owned\nimport Policy from '../policy.js'\n// module vars\nconst { assertPositive } = TypeAssert\nexport default class FixedIncreasePolicy extends Policy {\n /**\n * each call to _next() increases the interval by \"increasement\".\n * @param {number} increasement - The fixed interval (in milliseconds) between retry attempts.\n */\n constructor (increasement) {\n super()\n assertPositive(increasement, 'increasement')\n this._increasement = increasement\n }\n\n set increasement (increasement) {\n assertPositive(increasement, 'increasement')\n this._increasement = increasement\n }\n\n get increasement () {\n return this._increasement\n }\n\n /**\n * Interval ms of next execution\n * @param {number} retries\n * @returns {number}\n */\n _next (retries) {\n if (this._nextInterval >= this._max) {\n return this._max\n }\n return this._nextInterval + this.increasement\n }\n}\nexport { FixedIncreasePolicy as FixedIncreasePolicyType }\n","// 3rd\n// internal\nimport { TypeAssert } from '@creejs/commons-lang'\n// owned\nimport Policy from '../policy.js'\n// module vars\nconst { assertPositive } = TypeAssert\n\nexport default class FactoreIncreasePolicy extends Policy {\n /**\n * each call to _next() increases the interval by lastInterval * factor\n * @param {number} factor - the increasement factor, >= 1\n */\n constructor (factor) {\n super()\n assertPositive(factor, 'factor')\n if (factor < 1) {\n throw new Error('factor must be >= 1')\n }\n this._factor = factor\n }\n\n set factor (factor) {\n assertPositive(factor, 'factor')\n if (factor < 1) {\n throw new Error('factor must be >= 1')\n }\n this._factor = factor\n }\n\n get factor () {\n return this._factor\n }\n\n /**\n * Interval ms of next execution\n * @param {number} retries\n * @returns {number}\n */\n _next (retries) {\n if (this._nextInterval >= this._max) {\n return this._max\n }\n return this._nextInterval * this.factor\n }\n}\nexport { FactoreIncreasePolicy as FactoreIncreasePolicyType }\n","// 3rd\n// internal\nimport { TypeAssert } from '@creejs/commons-lang'\n\n// owned\nimport Policy from '../policy.js'\n// module vars\nconst { assertPositive } = TypeAssert\n\nexport default class ShuttlePolicy extends Policy {\n /**\n * the inteval value shuttles between min and max\n * @param {number} stepLength - the step length to change\n */\n constructor (stepLength) {\n super()\n assertPositive(stepLength, 'stepLength')\n this._stepLength = stepLength\n this.increasement = stepLength\n }\n\n set stepLength (stepLength) {\n assertPositive(stepLength, 'stepLength')\n this._stepLength = stepLength\n this.increasement = stepLength\n }\n\n get stepLength () {\n return this._stepLength\n }\n\n /**\n * Interval ms of next execution\n * @param {number} retries\n * @returns {number}\n * @throws {Error} Always throws \"Not Implemented Yet\" error.\n */\n _next (retries) {\n const nextInterval = this._nextInterval + this.increasement\n if (nextInterval >= this._max) {\n this.increasement = -this.stepLength\n return this._max\n } else if (nextInterval <= this._min) {\n this.increasement = this.stepLength\n return this._min\n }\n return nextInterval\n }\n}\n\nexport { ShuttlePolicy as ShuttlePolicyType }\n","// internal\nimport { TypeAssert } from '@creejs/commons-lang'\n// owned\nimport FixedInterval from './fixed-interval-policy.js'\n// module vars\nconst { assertNotNegative } = TypeAssert\n/**\n * @class FixedBackoff\n */\nexport default class FixedBackoff extends FixedInterval {\n /**\n * Creates a fixed backoff policy with optional jitter.\n * @param {number} fixedInterval - The fixed interval between retries in milliseconds.\n * @param {number} [jitter=500] - The maximum random jitter to add to the interval in milliseconds.\n */\n constructor (fixedInterval, jitter = 500) {\n super(fixedInterval)\n assertNotNegative(jitter, 'jitter')\n this._jitter = jitter ?? 500\n }\n}\n\nexport { FixedBackoff as FixedBackoffType }\n","// internal\nimport { TypeAssert } from '@creejs/commons-lang'\n// owned\nimport FactoreIncreasePolicy from './factor-increase-policy.js'\n\n// module vars\nconst { assertNotNegative } = TypeAssert\n/**\n * @class ExponentialBackoffPolicy\n */\nexport default class ExponentialBackoffPolicy extends FactoreIncreasePolicy {\n /**\n * Creates an exponential backoff policy with optional jitter.\n * @param {number} [jitter=500] - Maximum jitter in milliseconds to add to backoff intervals.\n */\n constructor (jitter = 500) {\n super(2)\n assertNotNegative(jitter, 'jitter')\n this._jitter = jitter ?? 500\n }\n}\n\nexport { ExponentialBackoffPolicy as ExponentialBackoffPolicyType }\n","// internal\nimport { TypeAssert } from '@creejs/commons-lang'\n// owned\nimport FixedIncreasePolicy from './fixed-increase-policy.js'\n// module vars\nconst { assertNotNegative } = TypeAssert\n/**\n * @class LinearBackoff\n */\nexport default class LinearBackoff extends FixedIncreasePolicy {\n /**\n * Creates a linear backoff policy with optional jitter.\n * @param {number} increasement - The base increasement value for backoff.\n * @param {number} [jitter=500] - The maximum jitter value to add to backoff (default: 500).\n */\n constructor (increasement, jitter = 500) {\n super(increasement)\n assertNotNegative(jitter, 'jitter')\n this._jitter = jitter ?? 500\n }\n}\n\nexport { LinearBackoff as LinearBackoffType }\n","import { TypeAssert } from '@creejs/commons-lang'\n// owned\n\n/**\n * @typedef {import('./retrier.js').default} Retrier\n */\n\n// module vars\nconst { assertNotNil, assertFunction } = TypeAssert\nexport default class Task {\n /**\n * Creates a new Task instance.\n * @param {Retrier} retrier - The retrier instance.\n * @param {Function} task - The function to be executed as the task.\n */\n constructor (retrier, task) {\n assertNotNil(retrier, 'retrier')\n assertFunction(task, 'task')\n this.retrier = retrier\n this.task = task\n this.result = undefined\n /** @type {Error|undefined} */\n this.error = undefined\n }\n\n get failed () {\n return this.error != null\n }\n\n get succeeded () {\n return this.error == null\n }\n\n /**\n * Executes the task with the given retry parameters.\n * 1. if execution throw error, keep error in this.error\n * 2. if execution return value, keep it in this.result\n * 3. always return Promise<void>\n * @param {number} retries - The number of retries attempted so far.\n * @param {number} latence - The current latency ms.\n * @param {number} nextInterval - The next interval ms.\n * @returns {Promise<void>} The result of the task execution.\n */\n async execute (retries, latence, nextInterval) {\n try {\n this.result = await this.task(retries, latence, nextInterval)\n this.error = undefined\n } catch (e) {\n this.error = e instanceof Error ? e : new Error(String(e))\n }\n }\n\n dispose () {\n // @ts-ignore\n this.retrier = undefined\n }\n}\n\nexport { Task as TaskType }\n","// owned\nimport Task from './task.js'\n\n/**\n * @typedef {import('./retrier.js').default} Retrier\n */\n\nexport default class AlwaysTask extends Task {\n /**\n * Checks if the given task is an instance of AlwaysTask.\n * @param {*} task - The task to check.\n * @returns {boolean} True if the task is an instance of AlwaysTask, false otherwise.\n */\n static isAlwaysTask (task) {\n return task instanceof AlwaysTask\n }\n\n /**\n * Creates an AlwaysTask instance.\n * @param {Retrier} retrier - The retrier instance to use for retry logic\n * @param {Function} task - The task function to execute\n * @param {boolean} resetRetryPolicyAfterSuccess - Whether to reset retry policy after successful execution\n */\n constructor (retrier, task, resetRetryPolicyAfterSuccess) {\n super(retrier, task)\n this.resetPolicy = resetRetryPolicyAfterSuccess\n }\n\n /**\n * Executes the task with the given retry parameters.\n * @param {number} retries - The number of retries attempted so far.\n * @param {number} latence - The current latency ms.\n * @param {number} nextInterval - The next interval ms.\n * @returns {Promise<*>} The result of the task execution.\n */\n async execute (retries, latence, nextInterval) {\n await super.execute(retries, latence, nextInterval)\n if (this.succeeded && this.resetPolicy) {\n this.retrier.resetRetryPolicy()\n }\n }\n}\n\nexport { AlwaysTask as AlwaysTaskType }\n","// owned\nimport Task from './task.js'\n\n/**\n * @typedef {import('./retrier.js').default} Retrier\n */\n\n/**\n * The task will execute forever despite of failure or success.\n * 1. Ignore Retrier total timeout setting\n * 2. Ignore Retrier max retries setting\n */\nexport default class ForeverTask extends Task {\n /**\n * Checks if the given task is an instance of ForeverTask.\n * @param {*} task - The task to check.\n * @returns {boolean} True if the task is an instance of ForeverTask, false otherwise.\n */\n static isForeverTask (task) {\n return task instanceof ForeverTask\n }\n\n /**\n * Creates an ForeverTask instance.\n * @param {Retrier} retrier - The retrier instance to use for retry logic\n * @param {Function} task - The task function to execute\n * @param {boolean} resetRetryPolicyAfterSuccess - Whether to reset retry policy after successful execution\n */\n constructor (retrier, task, resetRetryPolicyAfterSuccess) {\n super(retrier, task)\n this.resetPolicy = resetRetryPolicyAfterSuccess\n }\n\n /**\n * Executes the task with the given retry parameters.\n * @param {number} retries - The number of retries attempted so far.\n * @param {number} latence - The current latency ms.\n * @param {number} nextInterval - The next interval ms.\n * @returns {Promise<*>} The result of the task execution.\n */\n async execute (retries, latence, nextInterval) {\n await super.execute(retries, latence, nextInterval)\n if (this.succeeded && this.resetPolicy) {\n this.retrier.resetRetryPolicy()\n }\n }\n}\n\nexport { ForeverTask as AlwaysTaskType }\n","// internal\nimport { TypeAssert, TypeUtils, PromiseUtils } from '@creejs/commons-lang'\nimport { EventEmitter } from '@creejs/commons-events'\n\n// owned\nimport Event from './event.js'\nimport { DefaultMaxRetries } from './constants.js'\nimport FixedIntervalPolicy from './policy/fixed-interval-policy.js'\nimport FixedIncreasePolicy from './policy/fixed-increase-policy.js'\nimport FactoreIncreasePolicy from './policy/factor-increase-policy.js'\nimport ShuttlePolicy from './policy/shuttle-policy.js'\nimport FixedBackoff from './policy/fixed-backoff.js'\nimport ExponentialBackoffPolicy from './policy/exponential-backoff.js'\nimport LinearBackoff from './policy/linear-backoff.js'\nimport Task from './task.js'\nimport AlwaysTask from './alway-task.js'\nimport ForeverTask from './forever-task.js'\n\n/**\n * @typedef {import('./policy.js').default} Policy\n * @typedef {import('@creejs/commons-lang/types/promise-utils').Deferred} Deferred\n */\n\n// module vars\nconst { assertPositive, assertString, assertFunction, assertNumber } = TypeAssert\nconst { isNil } = TypeUtils\nconst TaskTimoutFlag = '!#@%$&^*'\n\n/**\n * @extends EventEmitter\n */\nexport default class Retrier {\n/*