@creejs/commons-retrier 2.1.13 → 2.1.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index-dev.cjs +25 -21
- package/dist/cjs/index-dev.cjs.map +1 -1
- package/dist/cjs/index-min.cjs +1 -1
- package/dist/cjs/index-min.cjs.map +1 -1
- package/dist/esm/index-dev.js +25 -21
- package/dist/esm/index-dev.js.map +1 -1
- package/dist/esm/index-min.js +1 -1
- package/dist/esm/index-min.js.map +1 -1
- package/dist/umd/index.dev.js +25 -21
- package/dist/umd/index.dev.js.map +1 -1
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +1 -1
package/dist/umd/index.dev.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CommonsLang = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
let r$1 = class r extends Error{static isAggregatedErrorLike(t){return t&&Array.isArray(t.errors)}static isAggregatedError(t){return t instanceof r}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),true)}};var e$1={constructorName:n$1,defaults:function(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) void 0===t[r]&&(t[r]=e[r]);return t},extend:o$1,extends:o$1,equals:function(t,r){if(t===r)return true;if("function"==typeof t?.equals)return t.equals(r);if("function"==typeof r?.equals)return r.equals(t);return false},isBrowser:i$1,isNode:function(){return !i$1()},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 n$1(t){return t?.constructor?.name}function o$1(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 i$1(){return "undefined"!=typeof window&&"undefined"!=typeof document}var s$1={isArray:u$1,isBoolean:f$1,isBuffer:function(t){return null!=t&&Buffer.isBuffer(t)},isFunction:a$1,isInstance:c$1,isIterable:function(t){return null!=t&&"function"==typeof t[Symbol.iterator]},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:d$1,isPositive:y,isNegative:h$1,isNotNegative:p$1,isNil:l$1,isNullOrUndefined:function(t){return null==t},isNull:g$1,isUndefined:w$1,isPlainObject:b$1,isObject:m$1,isPromise:A,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:E,isSymbol:N,isPrimitive:function(t){return null!==t&&("string"==typeof t||"number"==typeof t||"boolean"==typeof t)},isInt8Array:v$1,isUint8Array:O$1,isUint8ClampedArray:j,isInt16Array:P,isUint16Array:x,isInt32Array:S,isUint32Array:U,isFloat32Array:T,isFloat64Array:B,isBigInt64Array:I,isBigUint64Array:k$1,isTypedArray:$,isArrayBuffer:L$1};function u$1(t){return Array.isArray(t)}function f$1(t){return "boolean"==typeof t}function a$1(t){return "function"==typeof t}function c$1(t){return null!=t&&"object"==typeof t&&!b$1(t)}function l$1(t){return null==t}function y(t){return !!d$1(t)&&t>0}function p$1(t){return !!d$1(t)&&t>=0}function h$1(t){return !!d$1(t)&&t<0}function g$1(t){return null===t}function w$1(t){return void 0===t}function d$1(t){return null!=t&&"number"==typeof t}function m$1(t){return null!=t&&"object"==typeof t}function b$1(t){return null!==t&&"object"==typeof t&&(t.constructor===Object||void 0===t.constructor)}function A(t){return null!=t&&"function"==typeof t.then}function E(t){return null!=t&&"string"==typeof t}function N(t){return null!=t&&"symbol"==typeof t}function $(t){return ArrayBuffer.isView(t)&&t.constructor!==DataView}function v$1(t){return t instanceof Int8Array}function O$1(t){return t instanceof Uint8Array}function j(t){return t instanceof Uint8ClampedArray}function P(t){return t instanceof Int16Array}function x(t){return t instanceof Uint16Array}function S(t){return t instanceof Int32Array}function U(t){return t instanceof Uint32Array}function T(t){return t instanceof Float32Array}function B(t){return t instanceof Float64Array}function I(t){return t instanceof BigInt64Array}function k$1(t){return t instanceof BigUint64Array}function L$1(t){return t instanceof ArrayBuffer}var F={assertNumber:D,assertPositive:M,assertNotNegative:J,assertFunction:W,assertNotNil:V,assertString:q};function C(t,r){if(!Array.isArray(t))throw new Error(`${r?'"'+r+'" ':""}Not Array: type=${typeof t} value=${X(t)}`)}function q(t,r){if(!E(t))throw new Error(`${r?'"'+r+'" ':""}Not String: type=${typeof t} value=${X(t)}`)}function D(t,r){if(!d$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Number: type=${typeof t} value=${X(t)}`)}function M(t,r){if(!y(t))throw new Error(`${r?'"'+r+'" ':""}Not Positive: ${t}`)}function J(t,r){if(!p$1(t))throw new Error(`${r?'"'+r+'" ':""}Not "0 or Positive": ${t}`)}function W(t,r){if(!a$1(t))throw new Error(`${r?'"'+r+'" ':""}Not Function: type=${typeof t} value=${X(t)}`)}function H(t,r){if(!A(t))throw new Error(`${r?'"'+r+'" ':""}Not Promise: type=${typeof t} value=${X(t)}`)}function V(t,r){if(l$1(t))throw new Error((r?'"'+r+'" ':"")+"Should Not Nil")}function X(t){if(null===t)return "null";if(void 0===t)return "undefined";let r;try{r=JSON.stringify(t);}catch(e){r=t.toString();}return r}var tt={any:function(t){if(C(t),0===t.length)throw new Error("Empty Tasks");const e=rt(),n=[];for(let o=0;o<t.length;o++){const i=t[o];let u;if(s$1.isPromise(i))u=i;else {if(!s$1.isFunction(i)){n.push(new Error(`Invalid Task at index ${o}/${t.length-1}: ${i}`));continue}u=nt(i);}u.then(t=>{e.resolve(t);}).catch(o=>{n.push(o),n.length>=t.length&&e.reject(new r$1("All Tasks Failed",n));});}n.length===t.length&&e.reject(new r$1("All Tasks Failed",n));return e.promise},defer:rt,delay:function(t,r){s$1.isNumber(t)?(r=t,t=Promise.resolve()):null==t&&null==r&&(r=1,t=Promise.resolve());null!=t&&H(t),D(r=r??1e3);const e=rt(),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){H(t),D(r=r??1);const n=rt(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:et,returnValuePromised:nt,series:async function(t){C(t);const r=[];for(const e of t)if(W(e),s$1.isFunction(e))r.push(await nt(e));else {if(!s$1.isPromise(e))throw new Error(`Invalid Task: ${e}`);r.push(await e);}return r},seriesAllSettled:async function(t){C(t);const r=[];for(const e of t){W(e);try{r.push({ok:!0,result:await e()});}catch(t){r.push({ok:false,result:t});}}return r},parallel:async function(t,r=5){if(C(t),D(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>W(t));const e=[];if(t.length<=r){const r=await Promise.all(t.map(t=>nt(t)));return e.push(...r),e}const n=[];for(const o of t)if(W(o),n.push(o),n.length>=r){const t=await Promise.all(n.map(t=>nt(t)));e.push(...t),n.length=0;}if(n.length>0&&n.length<r){const t=await Promise.all(n.map(t=>nt(t)));e.push(...t);}return e},parallelAny:async function(t,e=5){if(C(t,"tasks"),D(e),0===t.length)throw new Error("Empty Tasks");if(e<=0)throw new Error(`Invalid maxParallel: ${e}, should > 0`);const n=[];let o=0,i=0;const u=rt();function f(){if(o>=t.length)return;if(i>e)return;const a=t[o++];let c;if(i++,s$1.isPromise(a))c=a;else {if(!s$1.isFunction(a))return n.push(new TypeError(`Invalid task: ${a}`)),void f();c=nt(a);}c.then(t=>{u.resolve(t);}).catch(e=>{n.push(e),n.length>=t.length&&u.pending?u.reject(new r$1("All Tasks Failed",n)):f();}).finally(()=>{i--;});}for(;i<e;)f();return u.promise},parallelAllSettled:async function(t,r=5){if(C(t),D(r),r<=0)throw new Error(`Invalid maxParallel: ${r}, should > 0`);t.forEach(t=>W(t));const e=[];if(t.length<=r){const r=await et(t.map(t=>nt(t)));return e.push(...r),e}const n=[];for(const o of t)if(n.push(o),n.length>=r){const t=await et(n.map(t=>nt(t)));e.push(...t),n.length=0;}if(n.length>0&&n.length<r){const t=await et(n.map(t=>nt(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 rt(t=-1,r){D(t);const e={};let n;return e.pending=true,e.canceled=false,e.rejected=false,e.resolved=false,t>=0&&(e.timerCleared=false,e.timerHandler=n=setTimeout(()=>{clearTimeout(n),e.timerCleared=true,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=true),e.pending=false,e.canceled=false,e.rejected=false,e.resolved=true,t(r));},e.reject=t=>{e.resolved||e.rejected||e.canceled||(null!=n&&(clearTimeout(n),e.timerCleared=true),e.pending=false,e.canceled=false,e.resolved=false,e.rejected=true,r(t));};}),e.cancel=e.promise.cancel=t=>{e.resolved||e.rejected||e.canceled||(null!=n&&(clearTimeout(n),e.timerCleared=true),e.reject(t??new Error("Cancelled")),e.canceled=e.promise.canceled=true);},e}async function et(t){C(t);const r=await Promise.allSettled(t),e=[];for(const t of r)"fulfilled"===t.status&&e.push({ok:true,result:t.value}),"rejected"===t.status&&e.push({ok:false,result:t.reason});return e}function nt(t){try{const r=t();return s$1.isPromise(r)?r:Promise.resolve(r)}catch(t){return Promise.reject(t)}}new TextDecoder;new TextEncoder;
|
|
8
8
|
|
|
9
9
|
// module vars
|
|
10
10
|
const DefaultMinInterval = 50;
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
// internal
|
|
15
15
|
|
|
16
16
|
// module vars
|
|
17
|
-
const { assertPositive: assertPositive$5, assertNotNegative: assertNotNegative$3 } =
|
|
18
|
-
const { isNumber } =
|
|
17
|
+
const { assertPositive: assertPositive$5, assertNotNegative: assertNotNegative$3 } = F;
|
|
18
|
+
const { isNumber } = s$1;
|
|
19
19
|
|
|
20
20
|
class Policy {
|
|
21
21
|
/**
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
var e={isFunction:t,isNil:s};function t(e){return "function"==typeof e}function s(e){return null==e}function n(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+'" ':"
|
|
159
|
+
var e={isFunction:t,isNil:s};function t(e){return "function"==typeof e}function s(e){return null==e}function n(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,s){if(!t(e))throw new Error(`${s?'"'+s+'" ':""}Not Function: type=${typeof e} value=${i(e)}`)},assertNotNil:function(e,t){if(s(e))throw new Error((t?'"'+t+'" ':"")+"Should Not Nil")},assertString:function(e,t){if(!n(e))throw new Error(`${t?'"'+t+'" ':""}Not String: type=${typeof e} value=${i(e)}`)},assertStringOrSymbol:function(e,t){if(!n(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){let t;try{t=JSON.stringify(e);}catch(s){t=e.toString();}return t}new TextDecoder,new TextEncoder;const l="DOwner$#$",{assertFunction:a,assertNotNil:o}=r;class c{constructor(e,t,s=false){o(e,"event"),a(t,"callback"),this._event=e,this._callback=t,this._isOnce=!!s,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 false;for(const t of [...this._listeners])t.invoke(...e);return true}emitOwner(e,...t){if(0===this._listeners.length)return false;const s=this._owner2Listeners.get(e);if(null==s)return false;for(const e of [...s])e.invoke(...t);return true}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,false,false)}prependListener(e,t){return this._addListener(e,t,false,true)}addOnceListener(e,t){return this._addListener(e,t,true,false)}prependOnceListener(e,t){return this._addListener(e,t,true,true)}_addListener(e,t,s,n){if(u(e))return false;f(e),this._callbacks.has(e)||this._callbacks.add(e),t=t??l;const r=new c(this,e,s);r.owner=t,n?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),true}removeListener(e){if(u(e))return false;if(!this._callbacks.has(e))return false;this._callbacks.delete(e);const t=this._callback2Listeners.get(e);if(null==t)return false;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 s=this._owner2Listeners.get(t);null!=s&&(s.delete(e),0===s.size&&this._owner2Listeners.delete(t));}return true}_remove(e){const t=this._listeners.indexOf(e);-1!==t&&this._listeners.splice(t,1);const{callback:s}=e,n=this._callback2Listeners.get(s);null!=n&&(n.delete(e),0===n.size&&(this._callback2Listeners.delete(s),this._callbacks.delete(s)));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,s=this._callback2Listeners.get(t);null!=s&&(s.delete(e),0===s.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 s of b){const n=t[s];e[s]=n.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;}addListener(e,t,s){return this.on(e,t,s)}prependListener(e,t,s){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependListener(t,s),this}prependOnceListener(e,t,s){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).prependOnceListener(t,s),this}emit(e,...t){const s=this._name2Event.get(e);return null!=s&&!s.isEmpty()&&(s.emit(...t),true)}emitOwner(e,t,...s){if(null==t)throw new Error('Missing "owner"');const n=this._name2Event.get(e);return null!=n&&!n.isEmpty()&&(n.emitOwner(t,...s),true)}eventNames(){return [...this._name2Event.keys()]}getMaxListeners(){return this._maxListeners}listenerCount(e,t){g(e,"eventName");const s=this._name2Event.get(e);return null==s||s.isEmpty()?0:s.listenerCount(t)}listeners(e){g(e,"eventName");const t=this._name2Event.get(e);return null==t||t.isEmpty()?[]:t.callbacks()}off(e,t){const s=this._name2Event.get(e);return null==s?this:(s.removeListener(t),s.isEmpty()?(this._name2Event.delete(e),this):this)}offAll(e,t){g(e,"eventName");const s=this._name2Event.get(e);return null==s?this:(s.removeAllListeners(t),s.isEmpty()?(this._name2Event.delete(e),this):this)}offOwner(e){p(e,"owner");const t=[...this._name2Event.values()];for(const s of t)s.removeAllListeners(e),s.isEmpty()&&this._name2Event.delete(s.name);return this}on(e,t,s){w(e),L(t),this._checkMaxListeners(e);return this._getOrCreateEvent(e).addListener(t,s),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,s){w(e),L(t);return this._getOrCreateEvent(e).addOnceListener(t,s),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 false;for(const t of this._name2Event.values())if(t.hasOwner(e))return true;return false}}
|
|
160
160
|
|
|
161
161
|
const Start = 'start'; // retry started
|
|
162
162
|
const Stop = 'stop'; // retry stopped
|
|
@@ -183,7 +183,7 @@
|
|
|
183
183
|
// 3rd
|
|
184
184
|
// internal
|
|
185
185
|
// module vars
|
|
186
|
-
const { assertPositive: assertPositive$4 } =
|
|
186
|
+
const { assertPositive: assertPositive$4 } = F;
|
|
187
187
|
class FixedIntervalPolicy extends Policy {
|
|
188
188
|
/**
|
|
189
189
|
* Creates a fixed interval retry policy with the specified interval.
|
|
@@ -218,7 +218,7 @@
|
|
|
218
218
|
// 3rd
|
|
219
219
|
// internal
|
|
220
220
|
// module vars
|
|
221
|
-
const { assertPositive: assertPositive$3 } =
|
|
221
|
+
const { assertPositive: assertPositive$3 } = F;
|
|
222
222
|
class FixedIncreasePolicy extends Policy {
|
|
223
223
|
/**
|
|
224
224
|
* each call to _next() increases the interval by "increasement".
|
|
@@ -255,7 +255,7 @@
|
|
|
255
255
|
// 3rd
|
|
256
256
|
// internal
|
|
257
257
|
// module vars
|
|
258
|
-
const { assertPositive: assertPositive$2 } =
|
|
258
|
+
const { assertPositive: assertPositive$2 } = F;
|
|
259
259
|
|
|
260
260
|
class FactoreIncreasePolicy extends Policy {
|
|
261
261
|
/**
|
|
@@ -299,7 +299,7 @@
|
|
|
299
299
|
// 3rd
|
|
300
300
|
// internal
|
|
301
301
|
// module vars
|
|
302
|
-
const { assertPositive: assertPositive$1 } =
|
|
302
|
+
const { assertPositive: assertPositive$1 } = F;
|
|
303
303
|
|
|
304
304
|
class ShuttlePolicy extends Policy {
|
|
305
305
|
/**
|
|
@@ -344,7 +344,7 @@
|
|
|
344
344
|
|
|
345
345
|
// internal
|
|
346
346
|
// module vars
|
|
347
|
-
const { assertNotNegative: assertNotNegative$2 } =
|
|
347
|
+
const { assertNotNegative: assertNotNegative$2 } = F;
|
|
348
348
|
/**
|
|
349
349
|
* @class FixedBackoff
|
|
350
350
|
*/
|
|
@@ -364,7 +364,7 @@
|
|
|
364
364
|
// internal
|
|
365
365
|
|
|
366
366
|
// module vars
|
|
367
|
-
const { assertNotNegative: assertNotNegative$1 } =
|
|
367
|
+
const { assertNotNegative: assertNotNegative$1 } = F;
|
|
368
368
|
/**
|
|
369
369
|
* @class ExponentialBackoffPolicy
|
|
370
370
|
*/
|
|
@@ -382,7 +382,7 @@
|
|
|
382
382
|
|
|
383
383
|
// internal
|
|
384
384
|
// module vars
|
|
385
|
-
const { assertNotNegative } =
|
|
385
|
+
const { assertNotNegative } = F;
|
|
386
386
|
/**
|
|
387
387
|
* @class LinearBackoff
|
|
388
388
|
*/
|
|
@@ -406,7 +406,7 @@
|
|
|
406
406
|
*/
|
|
407
407
|
|
|
408
408
|
// module vars
|
|
409
|
-
const { assertNotNil, assertFunction: assertFunction$1 } =
|
|
409
|
+
const { assertNotNil, assertFunction: assertFunction$1 } = F;
|
|
410
410
|
class Task {
|
|
411
411
|
/**
|
|
412
412
|
* Creates a new Task instance.
|
|
@@ -506,8 +506,8 @@
|
|
|
506
506
|
*/
|
|
507
507
|
|
|
508
508
|
// module vars
|
|
509
|
-
const { assertPositive, assertString, assertFunction, assertNumber } =
|
|
510
|
-
const { isNil } =
|
|
509
|
+
const { assertPositive, assertString, assertFunction, assertNumber } = F;
|
|
510
|
+
const { isNil } = s$1;
|
|
511
511
|
const TaskTimoutFlag = '!#@%$&^*';
|
|
512
512
|
|
|
513
513
|
/**
|
|
@@ -708,7 +708,7 @@
|
|
|
708
708
|
* @param {number} [fixedInterval=1000] - The fixed interval in milliseconds between retry attempts. Defaults to 1000ms if not provided.
|
|
709
709
|
*/
|
|
710
710
|
constructor (fixedInterval) {
|
|
711
|
-
|
|
711
|
+
k.mixin(this);
|
|
712
712
|
/**
|
|
713
713
|
* @type {Policy}
|
|
714
714
|
*/
|
|
@@ -1036,7 +1036,7 @@
|
|
|
1036
1036
|
let lastError;
|
|
1037
1037
|
// @ts-ignore
|
|
1038
1038
|
this.emit(Event.Start, startAt);
|
|
1039
|
-
this._taskingFlag =
|
|
1039
|
+
this._taskingFlag = tt.defer();
|
|
1040
1040
|
let latency = null;
|
|
1041
1041
|
|
|
1042
1042
|
/**
|
|
@@ -1076,7 +1076,7 @@
|
|
|
1076
1076
|
const nextDelay = this._policy.generate(this._currentRetries);
|
|
1077
1077
|
try {
|
|
1078
1078
|
try {
|
|
1079
|
-
await
|
|
1079
|
+
await tt.timeout(task.execute(this._currentRetries, latency, nextDelay), this._taskTimeout, TaskTimoutFlag);
|
|
1080
1080
|
} catch (err) {
|
|
1081
1081
|
// @ts-ignore
|
|
1082
1082
|
if (err.message === TaskTimoutFlag) {
|
|
@@ -1118,7 +1118,7 @@
|
|
|
1118
1118
|
break
|
|
1119
1119
|
}
|
|
1120
1120
|
// use Waiter to introduce the ability to wakeup at any time
|
|
1121
|
-
this._sleepWaiter =
|
|
1121
|
+
this._sleepWaiter = tt.wait(nextDelay);
|
|
1122
1122
|
await this._sleepWaiter.promise;
|
|
1123
1123
|
// await PromiseUtils.delay(nextDelay)
|
|
1124
1124
|
}
|
|
@@ -1129,6 +1129,10 @@
|
|
|
1129
1129
|
// @ts-ignore
|
|
1130
1130
|
this.emit(Event.Completed, this._currentRetries, spent);
|
|
1131
1131
|
});
|
|
1132
|
+
if (AlwaysTask.isAlwaysTask(this._task)) {
|
|
1133
|
+
return // always task, resolve with <void>
|
|
1134
|
+
}
|
|
1135
|
+
// normal retry task, return the task's result
|
|
1132
1136
|
return this._taskingFlag.promise
|
|
1133
1137
|
}
|
|
1134
1138
|
|
|
@@ -1141,7 +1145,7 @@
|
|
|
1141
1145
|
return
|
|
1142
1146
|
}
|
|
1143
1147
|
if (this._sleepWaiter != null) {
|
|
1144
|
-
this._sleepWaiter.
|
|
1148
|
+
this._sleepWaiter.wakeup();
|
|
1145
1149
|
}
|
|
1146
1150
|
}
|
|
1147
1151
|
|
|
@@ -1160,7 +1164,7 @@
|
|
|
1160
1164
|
// @ts-ignore
|
|
1161
1165
|
return this._breakFlag.promise
|
|
1162
1166
|
}
|
|
1163
|
-
this._breakFlag =
|
|
1167
|
+
this._breakFlag = tt.defer();
|
|
1164
1168
|
/** @type {Error|undefined} */
|
|
1165
1169
|
this._breakReason = reason ?? new Error('Manually Stop');
|
|
1166
1170
|
// @ts-ignore
|
|
@@ -1522,7 +1526,7 @@
|
|
|
1522
1526
|
* ...
|
|
1523
1527
|
* ```
|
|
1524
1528
|
*/
|
|
1525
|
-
|
|
1529
|
+
e$1.defaults(Retrier, RetrierFactory);
|
|
1526
1530
|
|
|
1527
1531
|
/**
|
|
1528
1532
|
* default export to support
|