@creejs/commons-retrier 2.1.6 → 2.1.8
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 +201 -23
- 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 +199 -24
- 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 +201 -23
- 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 +3 -3
- package/types/index.d.ts +6 -0
- package/types/policy/exponential-backoff.d.ts +12 -0
- package/types/policy/fixed-backoff.d.ts +13 -0
- package/types/policy/linear-backoff.d.ts +13 -0
- package/types/policy.d.ts +15 -5
- package/types/retrier-factory.d.ts +23 -0
- package/types/retrier.d.ts +20 -0
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 t$1={constructorName:function(t){return t?.constructor?.name},defaults:function(t,...e){if(null==t)throw new TypeError('"target" must not be null or undefined');for(const n of e)if(null!=n)for(const e in n) void 0===t[e]&&(t[e]=n[e]);return t},extend:e$1,extends:e$1,equals:function(t,e){if(t===e)return true;if("function"==typeof t?.equals)return t.equals(e);if("function"==typeof e?.equals)return e.equals(t);return false},isBrowser:n$1,isNode:function(){return !n$1()}};function e$1(t,...e){if(null==t)throw new TypeError('"target" must not be null or undefined');for(const n of e)if(null!=n)for(const e in n)t[e]=n[e];return t}function n$1(){return "undefined"!=typeof window&&"undefined"!=typeof document}var r$1={isNumber:
|
|
7
|
+
var t$1={constructorName:function(t){return t?.constructor?.name},defaults:function(t,...e){if(null==t)throw new TypeError('"target" must not be null or undefined');for(const n of e)if(null!=n)for(const e in n) void 0===t[e]&&(t[e]=n[e]);return t},extend:e$1,extends:e$1,equals:function(t,e){if(t===e)return true;if("function"==typeof t?.equals)return t.equals(e);if("function"==typeof e?.equals)return e.equals(t);return false},isBrowser:n$1,isNode:function(){return !n$1()}};function e$1(t,...e){if(null==t)throw new TypeError('"target" must not be null or undefined');for(const n of e)if(null!=n)for(const e in n)t[e]=n[e];return t}function n$1(){return "undefined"!=typeof window&&"undefined"!=typeof document}var r$1={isNumber:h$1,isNil:f$1};function s$1(t){return "function"==typeof t}function f$1(t){return null==t}function l$1(t){return !!h$1(t)&&t>0}function c$1(t){return !!h$1(t)&&t>=0}function h$1(t){return null!=t&&"number"==typeof t}function d$1(t){return null!=t&&"function"==typeof t.then}function m$1(t){return null!=t&&"string"==typeof t}var b$1={assertNumber:v$1,assertPositive:function(t,e){if(!l$1(t))throw new Error(`${e?'"'+e+'" ':" "}Not Positive: ${t}`)},assertNotNegative:function(t,e){if(!c$1(t))throw new Error(`${e?'"'+e+'" ':" "}Not "0 or Positive": ${t}`)},assertFunction:S,assertNotNil:function(t,e){if(f$1(t))throw new Error((e?'"'+e+'" ':" ")+"Should Not Nil")},assertString:O$1};function $(t,e){if(!Array.isArray(t))throw new Error(`${e?e+"":" "}Not Array: type=${typeof t} value=${JSON.stringify(t)}`)}function O$1(t,e){if(!m$1(t))throw new Error(`${e?'"'+e+'" ':" "}Not String: type=${typeof t} value=${JSON.stringify(t)}`)}function v$1(t,e){if(!h$1(t))throw new Error(`${e?'"'+e+'" ':" "}Not Number: type=${typeof t} value=${JSON.stringify(t)}`)}function S(t,e){if(!s$1(t))throw new Error(`${e?'"'+e+'" ':" "}Not Function: type=${typeof t} value=${JSON.stringify(t)}`)}function P(t,e){if(!d$1(t))throw new Error(`${e?'"'+e+'" ':" "}Not Promise: type=${typeof t} value=${JSON.stringify(t)}`)}var B={defer:U,delay:function(t,e){h$1(t)?(e=t,t=Promise.resolve()):null==t&&null==e&&(e=1,t=Promise.resolve());null!=t&&P(t),v$1(e=e??1e3);const n=U(),r=Date.now();return t.then((...t)=>{const o=Date.now()-r;o<e?setTimeout(()=>n.resolve(...t),e-o):n.resolve(...t);}).catch(t=>{const o=Date.now()-r;o<e?setTimeout(()=>n.reject(t),e-o):n.reject(t);}),n.promise},timeout:function(t,e,n){P(t),v$1(e=e??1);const r=U(e,n),o=Date.now();return t.then((...t)=>{Date.now()-o<=e?r.resolve(...t):r.reject(new Error(n??`Promise Timeout: ${e}ms`));}).catch(t=>{!r.resolved&&!r.rejected&&r.reject(t);}),r.promise},allSettled:C,returnValuePromised:I,series:async function(t){$(t);const e=[];for(const n of t)S(n),e.push(await n());return e},seriesAllSettled:async function(t){$(t);const e=[];for(const n of t){S(n);try{e.push({ok:!0,result:await n()});}catch(t){e.push({ok:false,result:t});}}return e},parallel:async function(t,e=5){if($(t),v$1(e),e<=0)throw new Error(`Invalid maxParallel: ${e}, should > 0`);t.forEach(t=>S(t));const n=[];if(t.length<=e){const e=await Promise.all(t.map(t=>I(t)));return n.push(...e),n}const r=[];for(const o of t)if(S(o),r.push(o),r.length>=e){const t=await Promise.all(r.map(t=>I(t)));n.push(...t),r.length=0;}if(r.length>0&&r.length<e){const t=await Promise.all(r.map(t=>I(t)));n.push(...t);}return n},parallelAllSettled:async function(t,e=5){if($(t),v$1(e),e<=0)throw new Error(`Invalid maxParallel: ${e}, should > 0`);t.forEach(t=>S(t));const n=[];if(t.length<=e){const e=await C(t.map(t=>I(t)));return n.push(...e),n}const r=[];for(const o of t)if(S(o),r.push(o),r.length>=e){const t=await C(r.map(t=>I(t)));n.push(...t),r.length=0;}if(r.length>0&&r.length<e){const t=await C(r.map(t=>I(t)));n.push(...t);}return n}};function U(t=-1,e){v$1(t);const n={};let r;return t>=0&&(n.timerHandler=r=setTimeout(()=>{clearTimeout(r),n.timerCleared=true,n.reject(new Error(e??`Promise Timeout: ${t}ms`));},t),n.timerHandler=r),n.promise=new Promise((t,e)=>{n.resolve=(...e)=>{null!=r&&(clearTimeout(r),n.timerCleared=true),n.resolved=true,t(...e);},n.reject=t=>{null!=r&&(clearTimeout(r),n.timerCleared=true),n.rejected=true,e(t);};}),n.promise.cancel=()=>{null!=r&&(clearTimeout(r),n.timerCleared=true),n.rejected=true,n.canceled=n.promise.canceled=true,n.reject(new Error("Cancelled"));},n}async function C(t){$(t);const e=await Promise.allSettled(t),n=[];for(const t of e)"fulfilled"===t.status&&n.push({ok:true,result:t.value}),"rejected"===t.status&&n.push({ok:false,result:t.reason});return n}function I(t){try{const e=t();return d$1(e)?e:Promise.resolve(e)}catch(t){return Promise.reject(t)}}
|
|
8
8
|
|
|
9
9
|
// module vars
|
|
10
10
|
const DefaultMinInterval = 50;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
// internal
|
|
15
15
|
|
|
16
16
|
// module vars
|
|
17
|
-
const { assertPositive: assertPositive$5 } = b$1;
|
|
17
|
+
const { assertPositive: assertPositive$5, assertNotNegative: assertNotNegative$3 } = b$1;
|
|
18
18
|
const { isNumber } = r$1;
|
|
19
19
|
|
|
20
20
|
class Policy {
|
|
@@ -25,13 +25,25 @@
|
|
|
25
25
|
this._min = DefaultMinInterval;
|
|
26
26
|
this._max = DefaultMaxInterval;
|
|
27
27
|
this._nextInterval = this._min;
|
|
28
|
+
this._jitter = 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get jitter () {
|
|
32
|
+
return this._jitter
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
set jitter (jitter) {
|
|
36
|
+
assertNotNegative$3(jitter, 'jitter');
|
|
37
|
+
this._jitter = jitter;
|
|
28
38
|
}
|
|
29
39
|
|
|
30
40
|
/**
|
|
31
41
|
* Copies settings to target policy.
|
|
42
|
+
* 1. range
|
|
43
|
+
* 2. nextInterval value
|
|
32
44
|
* @param {Policy} targetPolicy - The policy to modify.
|
|
33
45
|
*/
|
|
34
|
-
|
|
46
|
+
copyPolicySettingTo (targetPolicy) {
|
|
35
47
|
targetPolicy.range(this._min, this._max);
|
|
36
48
|
targetPolicy._nextInterval = this._nextInterval;
|
|
37
49
|
}
|
|
@@ -106,20 +118,25 @@
|
|
|
106
118
|
|
|
107
119
|
/**
|
|
108
120
|
* Interval ms of next execution
|
|
121
|
+
* @param {number} retries current retry times
|
|
109
122
|
* @returns {number}
|
|
110
|
-
* @throws {Error} Always throws "Not Implemented Yet" error.
|
|
111
123
|
*/
|
|
112
|
-
generate () {
|
|
124
|
+
generate (retries) {
|
|
113
125
|
const rtnVal = this._nextInterval;
|
|
114
|
-
this._increase();
|
|
126
|
+
this._increase(retries);
|
|
115
127
|
return rtnVal
|
|
116
128
|
}
|
|
117
129
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
130
|
+
/**
|
|
131
|
+
* @param {number} retries current retry times
|
|
132
|
+
* @returns {number}
|
|
133
|
+
*/
|
|
134
|
+
_increase (retries) {
|
|
135
|
+
const generated = this._next(retries);
|
|
136
|
+
if (!isNumber(generated)) {
|
|
121
137
|
throw new Error('Generated Next Interval Not Number')
|
|
122
138
|
}
|
|
139
|
+
const nextInterval = this._jitter <= 0 ? generated : generated + Math.floor(Math.random() * this._jitter);
|
|
123
140
|
if (nextInterval < this._min) {
|
|
124
141
|
return (this._nextInterval = this._min)
|
|
125
142
|
} else if (nextInterval > this._max) {
|
|
@@ -130,10 +147,11 @@
|
|
|
130
147
|
|
|
131
148
|
/**
|
|
132
149
|
* subclass should implement this method
|
|
150
|
+
* @param {number} retries current retry times
|
|
133
151
|
* @returns {number} The interval in milliseconds to wait before the next retry attempt.
|
|
134
152
|
* @protected
|
|
135
153
|
*/
|
|
136
|
-
_next () {
|
|
154
|
+
_next (retries) {
|
|
137
155
|
throw new Error('Not Impled Yet')
|
|
138
156
|
}
|
|
139
157
|
}
|
|
@@ -188,10 +206,11 @@
|
|
|
188
206
|
|
|
189
207
|
/**
|
|
190
208
|
* Interval ms of next execution
|
|
209
|
+
* @param {number} retries
|
|
191
210
|
* @returns {number}
|
|
192
211
|
* @throws {Error} Always throws "Not Implemented Yet" error.
|
|
193
212
|
*/
|
|
194
|
-
_next () {
|
|
213
|
+
_next (retries) {
|
|
195
214
|
return this.interval
|
|
196
215
|
}
|
|
197
216
|
}
|
|
@@ -222,9 +241,10 @@
|
|
|
222
241
|
|
|
223
242
|
/**
|
|
224
243
|
* Interval ms of next execution
|
|
244
|
+
* @param {number} retries
|
|
225
245
|
* @returns {number}
|
|
226
246
|
*/
|
|
227
|
-
_next () {
|
|
247
|
+
_next (retries) {
|
|
228
248
|
if (this._nextInterval >= this._max) {
|
|
229
249
|
return this._max
|
|
230
250
|
}
|
|
@@ -265,9 +285,10 @@
|
|
|
265
285
|
|
|
266
286
|
/**
|
|
267
287
|
* Interval ms of next execution
|
|
288
|
+
* @param {number} retries
|
|
268
289
|
* @returns {number}
|
|
269
290
|
*/
|
|
270
|
-
_next () {
|
|
291
|
+
_next (retries) {
|
|
271
292
|
if (this._nextInterval >= this._max) {
|
|
272
293
|
return this._max
|
|
273
294
|
}
|
|
@@ -304,10 +325,11 @@
|
|
|
304
325
|
|
|
305
326
|
/**
|
|
306
327
|
* Interval ms of next execution
|
|
328
|
+
* @param {number} retries
|
|
307
329
|
* @returns {number}
|
|
308
330
|
* @throws {Error} Always throws "Not Implemented Yet" error.
|
|
309
331
|
*/
|
|
310
|
-
_next () {
|
|
332
|
+
_next (retries) {
|
|
311
333
|
const nextInterval = this._nextInterval + this.increasement;
|
|
312
334
|
if (nextInterval >= this._max) {
|
|
313
335
|
this.increasement = -this.stepLength;
|
|
@@ -418,6 +440,63 @@
|
|
|
418
440
|
}
|
|
419
441
|
}
|
|
420
442
|
|
|
443
|
+
// internal
|
|
444
|
+
// module vars
|
|
445
|
+
const { assertNotNegative: assertNotNegative$2 } = b$1;
|
|
446
|
+
/**
|
|
447
|
+
* @class FixedBackoff
|
|
448
|
+
*/
|
|
449
|
+
class FixedBackoff extends FixedIntervalPolicy {
|
|
450
|
+
/**
|
|
451
|
+
* Creates a fixed backoff policy with optional jitter.
|
|
452
|
+
* @param {number} fixedInterval - The fixed interval between retries in milliseconds.
|
|
453
|
+
* @param {number} [jitter=500] - The maximum random jitter to add to the interval in milliseconds.
|
|
454
|
+
*/
|
|
455
|
+
constructor (fixedInterval, jitter = 500) {
|
|
456
|
+
super(fixedInterval);
|
|
457
|
+
assertNotNegative$2(jitter, 'jitter');
|
|
458
|
+
this._jitter = jitter ?? 500;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
// internal
|
|
463
|
+
|
|
464
|
+
// module vars
|
|
465
|
+
const { assertNotNegative: assertNotNegative$1 } = b$1;
|
|
466
|
+
/**
|
|
467
|
+
* @class ExponentialBackoffPolicy
|
|
468
|
+
*/
|
|
469
|
+
class ExponentialBackoffPolicy extends FactoreIncreasePolicy {
|
|
470
|
+
/**
|
|
471
|
+
* Creates an exponential backoff policy with optional jitter.
|
|
472
|
+
* @param {number} [jitter=500] - Maximum jitter in milliseconds to add to backoff intervals.
|
|
473
|
+
*/
|
|
474
|
+
constructor (jitter = 500) {
|
|
475
|
+
super(2);
|
|
476
|
+
assertNotNegative$1(jitter, 'jitter');
|
|
477
|
+
this._jitter = jitter ?? 500;
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// internal
|
|
482
|
+
// module vars
|
|
483
|
+
const { assertNotNegative } = b$1;
|
|
484
|
+
/**
|
|
485
|
+
* @class LinearBackoff
|
|
486
|
+
*/
|
|
487
|
+
class LinearBackoff extends FixedIncreasePolicy {
|
|
488
|
+
/**
|
|
489
|
+
* Creates a linear backoff policy with optional jitter.
|
|
490
|
+
* @param {number} increasement - The base increasement value for backoff.
|
|
491
|
+
* @param {number} [jitter=500] - The maximum jitter value to add to backoff (default: 500).
|
|
492
|
+
*/
|
|
493
|
+
constructor (increasement, jitter = 500) {
|
|
494
|
+
super(increasement);
|
|
495
|
+
assertNotNegative(jitter, 'jitter');
|
|
496
|
+
this._jitter = jitter ?? 500;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
421
500
|
// internal
|
|
422
501
|
|
|
423
502
|
// module vars
|
|
@@ -560,7 +639,27 @@
|
|
|
560
639
|
return this
|
|
561
640
|
}
|
|
562
641
|
const newPolicy = new FixedIntervalPolicy(fixedInterval);
|
|
563
|
-
oldPolicy?.
|
|
642
|
+
oldPolicy?.copyPolicySettingTo(newPolicy);
|
|
643
|
+
newPolicy.reset();
|
|
644
|
+
this._policy = newPolicy;
|
|
645
|
+
return this
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* sets a fixed backoff strategy.
|
|
650
|
+
* @param {number} fixedInterval - The fixed interval between retries in milliseconds.
|
|
651
|
+
* @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
|
|
652
|
+
* @returns {Retrier} A retrier instance configured with fixed backoff.
|
|
653
|
+
*/
|
|
654
|
+
fixedBackoff (fixedInterval, jitter = 500) {
|
|
655
|
+
const oldPolicy = this._policy;
|
|
656
|
+
if (oldPolicy instanceof FixedIntervalPolicy) {
|
|
657
|
+
oldPolicy.interval = fixedInterval;
|
|
658
|
+
oldPolicy.jitter = jitter;
|
|
659
|
+
return this
|
|
660
|
+
}
|
|
661
|
+
const newPolicy = new FixedBackoff(fixedInterval, jitter);
|
|
662
|
+
oldPolicy?.copyPolicySettingTo(newPolicy);
|
|
564
663
|
newPolicy.reset();
|
|
565
664
|
this._policy = newPolicy;
|
|
566
665
|
return this
|
|
@@ -578,7 +677,27 @@
|
|
|
578
677
|
return this
|
|
579
678
|
}
|
|
580
679
|
const newPolicy = new FixedIncreasePolicy(increasement);
|
|
581
|
-
oldPolicy?.
|
|
680
|
+
oldPolicy?.copyPolicySettingTo(newPolicy);
|
|
681
|
+
newPolicy.reset();
|
|
682
|
+
this._policy = newPolicy;
|
|
683
|
+
return this
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Sets a fixed increase policy for retry intervals.
|
|
688
|
+
* @param {number} increasement - The fixed amount to increase the interval by on each retry.
|
|
689
|
+
* @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
|
|
690
|
+
* @returns {this} The retrier instance for chaining.
|
|
691
|
+
*/
|
|
692
|
+
linearBackoff (increasement, jitter = 500) {
|
|
693
|
+
const oldPolicy = this._policy;
|
|
694
|
+
if (oldPolicy instanceof LinearBackoff) {
|
|
695
|
+
oldPolicy.increasement = increasement;
|
|
696
|
+
oldPolicy.jitter = jitter;
|
|
697
|
+
return this
|
|
698
|
+
}
|
|
699
|
+
const newPolicy = new LinearBackoff(increasement, jitter);
|
|
700
|
+
oldPolicy?.copyPolicySettingTo(newPolicy);
|
|
582
701
|
newPolicy.reset();
|
|
583
702
|
this._policy = newPolicy;
|
|
584
703
|
return this
|
|
@@ -596,7 +715,25 @@
|
|
|
596
715
|
return this
|
|
597
716
|
}
|
|
598
717
|
const newPolicy = new FactoreIncreasePolicy(factor);
|
|
599
|
-
oldPolicy?.
|
|
718
|
+
oldPolicy?.copyPolicySettingTo(newPolicy);
|
|
719
|
+
newPolicy.reset();
|
|
720
|
+
this._policy = newPolicy;
|
|
721
|
+
return this
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Creates a new Retrier instance with exponential-backoff strategy.
|
|
726
|
+
* @param {number} [jitter]
|
|
727
|
+
* @returns {Retrier} A new Retrier instance
|
|
728
|
+
*/
|
|
729
|
+
exponentialBackoff (jitter = 500) {
|
|
730
|
+
const oldPolicy = this._policy;
|
|
731
|
+
if (oldPolicy instanceof ExponentialBackoffPolicy) {
|
|
732
|
+
oldPolicy.jitter = jitter;
|
|
733
|
+
return this
|
|
734
|
+
}
|
|
735
|
+
const newPolicy = new ExponentialBackoffPolicy(jitter);
|
|
736
|
+
oldPolicy?.copyPolicySettingTo(newPolicy);
|
|
600
737
|
newPolicy.reset();
|
|
601
738
|
this._policy = newPolicy;
|
|
602
739
|
return this
|
|
@@ -614,7 +751,7 @@
|
|
|
614
751
|
return this
|
|
615
752
|
}
|
|
616
753
|
const newPolicy = new ShuttlePolicy(stepLength);
|
|
617
|
-
oldPolicy?.
|
|
754
|
+
oldPolicy?.copyPolicySettingTo(newPolicy);
|
|
618
755
|
newPolicy.reset();
|
|
619
756
|
this._policy = newPolicy;
|
|
620
757
|
return this
|
|
@@ -694,7 +831,7 @@
|
|
|
694
831
|
let lastError = null;
|
|
695
832
|
// @ts-ignore
|
|
696
833
|
this.emit(Event.Start, startAt);
|
|
697
|
-
this._taskingFlag =
|
|
834
|
+
this._taskingFlag = B.defer();
|
|
698
835
|
let latency = null;
|
|
699
836
|
while (true) {
|
|
700
837
|
// need to stop?
|
|
@@ -721,10 +858,10 @@
|
|
|
721
858
|
// @ts-ignore
|
|
722
859
|
this.emit(Event.Retry, this._currentRetries, latency);
|
|
723
860
|
const task = this._task; // take task, it may be changed in events' callback functions
|
|
724
|
-
const nextDelay = this._policy.generate();
|
|
861
|
+
const nextDelay = this._policy.generate(this._currentRetries);
|
|
725
862
|
try {
|
|
726
863
|
try {
|
|
727
|
-
await
|
|
864
|
+
await B.timeout(task.execute(this._currentRetries, latency, nextDelay), this._taskTimeout, TaskTimoutFlag);
|
|
728
865
|
} catch (err) {
|
|
729
866
|
// @ts-ignore
|
|
730
867
|
if (err.message === TaskTimoutFlag) {
|
|
@@ -765,7 +902,7 @@
|
|
|
765
902
|
this._taskingFlag.reject(lastError ?? new Error(`Max Retries Exceeded, Retring ${this._currentRetries} times > max ${this._maxRetries}`));
|
|
766
903
|
break
|
|
767
904
|
}
|
|
768
|
-
await
|
|
905
|
+
await B.delay(nextDelay);
|
|
769
906
|
}
|
|
770
907
|
this._taskingFlag.promise.finally(() => {
|
|
771
908
|
this.resetRetryPolicy();
|
|
@@ -792,7 +929,7 @@
|
|
|
792
929
|
// @ts-ignore
|
|
793
930
|
return this._breakFlag.promise
|
|
794
931
|
}
|
|
795
|
-
this._breakFlag =
|
|
932
|
+
this._breakFlag = B.defer();
|
|
796
933
|
this._breakReason = reason ?? new Error('Manually Stop');
|
|
797
934
|
// @ts-ignore
|
|
798
935
|
this.once(Event.Completed, () => {
|
|
@@ -1022,6 +1159,18 @@
|
|
|
1022
1159
|
return retrier
|
|
1023
1160
|
}
|
|
1024
1161
|
|
|
1162
|
+
/**
|
|
1163
|
+
* Creates a retrier with a fixed backoff strategy.
|
|
1164
|
+
* @param {number} fixedInterval - The fixed interval between retries in milliseconds.
|
|
1165
|
+
* @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
|
|
1166
|
+
* @returns {Retrier} A retrier instance configured with fixed backoff.
|
|
1167
|
+
*/
|
|
1168
|
+
function fixedBackoff (fixedInterval, jitter = 500) {
|
|
1169
|
+
const retrier = new Retrier();
|
|
1170
|
+
retrier.fixedBackoff(fixedInterval, jitter);
|
|
1171
|
+
return retrier
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1025
1174
|
/**
|
|
1026
1175
|
* Creates a retrier with a fixed increase strategy.
|
|
1027
1176
|
* @param {number} increasement - The fixed amount to increase on each retry.
|
|
@@ -1033,6 +1182,18 @@
|
|
|
1033
1182
|
return retrier
|
|
1034
1183
|
}
|
|
1035
1184
|
|
|
1185
|
+
/**
|
|
1186
|
+
* Creates a retrier with a fixed increase strategy.
|
|
1187
|
+
* @param {number} increasement - The fixed amount to increase on each retry.
|
|
1188
|
+
* @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
|
|
1189
|
+
* @returns {Retrier} A retrier instance configured with fixed increase.
|
|
1190
|
+
*/
|
|
1191
|
+
function linearBackoff (increasement, jitter = 500) {
|
|
1192
|
+
const retrier = new Retrier();
|
|
1193
|
+
retrier.linearBackoff(increasement, jitter);
|
|
1194
|
+
return retrier
|
|
1195
|
+
}
|
|
1196
|
+
|
|
1036
1197
|
/**
|
|
1037
1198
|
* Creates a new Retrier instance with factor-increase strategy.
|
|
1038
1199
|
* @param {number} factor - The factor by which to increase the interval on each retry.
|
|
@@ -1044,6 +1205,17 @@
|
|
|
1044
1205
|
return retrier
|
|
1045
1206
|
}
|
|
1046
1207
|
|
|
1208
|
+
/**
|
|
1209
|
+
* Creates a new Retrier instance with exponential-backoff strategy.
|
|
1210
|
+
* @param {number} [jitter=500]
|
|
1211
|
+
* @returns {Retrier} A new Retrier instance
|
|
1212
|
+
*/
|
|
1213
|
+
function exponentialBackoff (jitter = 500) {
|
|
1214
|
+
const retrier = new Retrier();
|
|
1215
|
+
retrier.exponentialBackoff(jitter);
|
|
1216
|
+
return retrier
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1047
1219
|
/**
|
|
1048
1220
|
* Creates a Retrier instance with a shuttle-interval strategt.
|
|
1049
1221
|
* @param {number} stepLength - The interval step length of each change
|
|
@@ -1098,8 +1270,11 @@
|
|
|
1098
1270
|
max,
|
|
1099
1271
|
range,
|
|
1100
1272
|
fixedInterval,
|
|
1273
|
+
fixedBackoff,
|
|
1101
1274
|
fixedIncrease,
|
|
1275
|
+
linearBackoff,
|
|
1102
1276
|
factorIncrease,
|
|
1277
|
+
exponentialBackoff,
|
|
1103
1278
|
shuttleInterval,
|
|
1104
1279
|
timeout,
|
|
1105
1280
|
taskTimeout,
|
|
@@ -1136,10 +1311,13 @@
|
|
|
1136
1311
|
exports.Retrier = Retrier;
|
|
1137
1312
|
exports.RetrierFactory = RetrierFactory;
|
|
1138
1313
|
exports.default = index;
|
|
1314
|
+
exports.exponentialBackoff = exponentialBackoff;
|
|
1139
1315
|
exports.factorIncrease = factorIncrease;
|
|
1316
|
+
exports.fixedBackoff = fixedBackoff;
|
|
1140
1317
|
exports.fixedIncrease = fixedIncrease;
|
|
1141
1318
|
exports.fixedInterval = fixedInterval;
|
|
1142
1319
|
exports.infinite = infinite;
|
|
1320
|
+
exports.linearBackoff = linearBackoff;
|
|
1143
1321
|
exports.max = max;
|
|
1144
1322
|
exports.maxRetries = maxRetries;
|
|
1145
1323
|
exports.min = min;
|