@creejs/commons-retrier 2.1.7 → 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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- 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:y,isNil:f$1};function s$1(t){return "function"==typeof t}function f$1(t){return null==t}function l$1(t){return !!y(t)&&t>0}function y(t){return null!=t&&"number"==typeof t}function w$1(t){return null!=t&&"function"==typeof t.then}function d$1(t){return null!=t&&"string"==typeof t}var b$1={assertNumber:$,assertPositive:function(t,e){if(!l$1(t))throw new Error(`${e?'"'+e+'" ':" "}Not Positive: ${t}`)},assertFunction:E,assertNotNil:function(t,e){if(f$1(t))throw new Error((e?'"'+e+'" ':" ")+"Should Not Nil")},assertString:O$1};function N(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(!d$1(t))throw new Error(`${e?'"'+e+'" ':" "}Not String: type=${typeof t} value=${JSON.stringify(t)}`)}function $(t,e){if(!y(t))throw new Error(`${e?'"'+e+'" ':" "}Not Number: type=${typeof t} value=${JSON.stringify(t)}`)}function E(t,e){if(!s$1(t))throw new Error(`${e?'"'+e+'" ':" "}Not Function: type=${typeof t} value=${JSON.stringify(t)}`)}function S(t,e){if(!w$1(t))throw new Error(`${e?'"'+e+'" ':" "}Not Promise: type=${typeof t} value=${JSON.stringify(t)}`)}var A={defer:B,delay:function(t,e){y(t)?(e=t,t=Promise.resolve()):null==t&&null==e&&(e=1,t=Promise.resolve());null!=t&&S(t),$(e=e??1e3);const n=B(),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){S(t),$(e=e??1);const r=B(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:U,returnValuePromised:C,series:async function(t){N(t);const e=[];for(const n of t)E(n),e.push(await n());return e},seriesAllSettled:async function(t){N(t);const e=[];for(const n of t){E(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(N(t),$(e),e<=0)throw new Error(`Invalid maxParallel: ${e}, should > 0`);t.forEach(t=>E(t));const n=[];if(t.length<=e){const e=await Promise.all(t.map(t=>C(t)));return n.push(...e),n}const r=[];for(const o of t)if(E(o),r.push(o),r.length>=e){const t=await Promise.all(r.map(t=>C(t)));n.push(...t),r.length=0;}if(r.length>0&&r.length<e){const t=await Promise.all(r.map(t=>C(t)));n.push(...t);}return n},parallelAllSettled:async function(t,e=5){if(N(t),$(e),e<=0)throw new Error(`Invalid maxParallel: ${e}, should > 0`);t.forEach(t=>E(t));const n=[];if(t.length<=e){const e=await U(t.map(t=>C(t)));return n.push(...e),n}const r=[];for(const o of t)if(E(o),r.push(o),r.length>=e){const t=await U(r.map(t=>C(t)));n.push(...t),r.length=0;}if(r.length>0&&r.length<e){const t=await U(r.map(t=>C(t)));n.push(...t);}return n}};function B(t=-1,e){$(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 U(t){N(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 C(t){try{const e=t();return w$1(e)?e:Promise.resolve(e)}catch(t){return Promise.reject(t)}}
5
+ 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)}}
6
6
 
7
7
  // module vars
8
8
  const DefaultMinInterval = 50;
@@ -12,7 +12,7 @@ const DefaultMaxRetries = 3;
12
12
  // internal
13
13
 
14
14
  // module vars
15
- const { assertPositive: assertPositive$5 } = b$1;
15
+ const { assertPositive: assertPositive$5, assertNotNegative: assertNotNegative$3 } = b$1;
16
16
  const { isNumber } = r$1;
17
17
 
18
18
  class Policy {
@@ -23,13 +23,25 @@ class Policy {
23
23
  this._min = DefaultMinInterval;
24
24
  this._max = DefaultMaxInterval;
25
25
  this._nextInterval = this._min;
26
+ this._jitter = 0;
27
+ }
28
+
29
+ get jitter () {
30
+ return this._jitter
31
+ }
32
+
33
+ set jitter (jitter) {
34
+ assertNotNegative$3(jitter, 'jitter');
35
+ this._jitter = jitter;
26
36
  }
27
37
 
28
38
  /**
29
39
  * Copies settings to target policy.
40
+ * 1. range
41
+ * 2. nextInterval value
30
42
  * @param {Policy} targetPolicy - The policy to modify.
31
43
  */
32
- copyPolicySetting (targetPolicy) {
44
+ copyPolicySettingTo (targetPolicy) {
33
45
  targetPolicy.range(this._min, this._max);
34
46
  targetPolicy._nextInterval = this._nextInterval;
35
47
  }
@@ -104,20 +116,25 @@ class Policy {
104
116
 
105
117
  /**
106
118
  * Interval ms of next execution
119
+ * @param {number} retries current retry times
107
120
  * @returns {number}
108
- * @throws {Error} Always throws "Not Implemented Yet" error.
109
121
  */
110
- generate () {
122
+ generate (retries) {
111
123
  const rtnVal = this._nextInterval;
112
- this._increase();
124
+ this._increase(retries);
113
125
  return rtnVal
114
126
  }
115
127
 
116
- _increase () {
117
- const nextInterval = this._next();
118
- if (!isNumber(nextInterval)) {
128
+ /**
129
+ * @param {number} retries current retry times
130
+ * @returns {number}
131
+ */
132
+ _increase (retries) {
133
+ const generated = this._next(retries);
134
+ if (!isNumber(generated)) {
119
135
  throw new Error('Generated Next Interval Not Number')
120
136
  }
137
+ const nextInterval = this._jitter <= 0 ? generated : generated + Math.floor(Math.random() * this._jitter);
121
138
  if (nextInterval < this._min) {
122
139
  return (this._nextInterval = this._min)
123
140
  } else if (nextInterval > this._max) {
@@ -128,10 +145,11 @@ class Policy {
128
145
 
129
146
  /**
130
147
  * subclass should implement this method
148
+ * @param {number} retries current retry times
131
149
  * @returns {number} The interval in milliseconds to wait before the next retry attempt.
132
150
  * @protected
133
151
  */
134
- _next () {
152
+ _next (retries) {
135
153
  throw new Error('Not Impled Yet')
136
154
  }
137
155
  }
@@ -186,10 +204,11 @@ class FixedIntervalPolicy extends Policy {
186
204
 
187
205
  /**
188
206
  * Interval ms of next execution
207
+ * @param {number} retries
189
208
  * @returns {number}
190
209
  * @throws {Error} Always throws "Not Implemented Yet" error.
191
210
  */
192
- _next () {
211
+ _next (retries) {
193
212
  return this.interval
194
213
  }
195
214
  }
@@ -220,9 +239,10 @@ class FixedIncreasePolicy extends Policy {
220
239
 
221
240
  /**
222
241
  * Interval ms of next execution
242
+ * @param {number} retries
223
243
  * @returns {number}
224
244
  */
225
- _next () {
245
+ _next (retries) {
226
246
  if (this._nextInterval >= this._max) {
227
247
  return this._max
228
248
  }
@@ -263,9 +283,10 @@ class FactoreIncreasePolicy extends Policy {
263
283
 
264
284
  /**
265
285
  * Interval ms of next execution
286
+ * @param {number} retries
266
287
  * @returns {number}
267
288
  */
268
- _next () {
289
+ _next (retries) {
269
290
  if (this._nextInterval >= this._max) {
270
291
  return this._max
271
292
  }
@@ -302,10 +323,11 @@ class ShuttlePolicy extends Policy {
302
323
 
303
324
  /**
304
325
  * Interval ms of next execution
326
+ * @param {number} retries
305
327
  * @returns {number}
306
328
  * @throws {Error} Always throws "Not Implemented Yet" error.
307
329
  */
308
- _next () {
330
+ _next (retries) {
309
331
  const nextInterval = this._nextInterval + this.increasement;
310
332
  if (nextInterval >= this._max) {
311
333
  this.increasement = -this.stepLength;
@@ -416,6 +438,63 @@ class AlwaysTask extends Task {
416
438
  }
417
439
  }
418
440
 
441
+ // internal
442
+ // module vars
443
+ const { assertNotNegative: assertNotNegative$2 } = b$1;
444
+ /**
445
+ * @class FixedBackoff
446
+ */
447
+ class FixedBackoff extends FixedIntervalPolicy {
448
+ /**
449
+ * Creates a fixed backoff policy with optional jitter.
450
+ * @param {number} fixedInterval - The fixed interval between retries in milliseconds.
451
+ * @param {number} [jitter=500] - The maximum random jitter to add to the interval in milliseconds.
452
+ */
453
+ constructor (fixedInterval, jitter = 500) {
454
+ super(fixedInterval);
455
+ assertNotNegative$2(jitter, 'jitter');
456
+ this._jitter = jitter ?? 500;
457
+ }
458
+ }
459
+
460
+ // internal
461
+
462
+ // module vars
463
+ const { assertNotNegative: assertNotNegative$1 } = b$1;
464
+ /**
465
+ * @class ExponentialBackoffPolicy
466
+ */
467
+ class ExponentialBackoffPolicy extends FactoreIncreasePolicy {
468
+ /**
469
+ * Creates an exponential backoff policy with optional jitter.
470
+ * @param {number} [jitter=500] - Maximum jitter in milliseconds to add to backoff intervals.
471
+ */
472
+ constructor (jitter = 500) {
473
+ super(2);
474
+ assertNotNegative$1(jitter, 'jitter');
475
+ this._jitter = jitter ?? 500;
476
+ }
477
+ }
478
+
479
+ // internal
480
+ // module vars
481
+ const { assertNotNegative } = b$1;
482
+ /**
483
+ * @class LinearBackoff
484
+ */
485
+ class LinearBackoff extends FixedIncreasePolicy {
486
+ /**
487
+ * Creates a linear backoff policy with optional jitter.
488
+ * @param {number} increasement - The base increasement value for backoff.
489
+ * @param {number} [jitter=500] - The maximum jitter value to add to backoff (default: 500).
490
+ */
491
+ constructor (increasement, jitter = 500) {
492
+ super(increasement);
493
+ assertNotNegative(jitter, 'jitter');
494
+ this._jitter = jitter ?? 500;
495
+ }
496
+ }
497
+
419
498
  // internal
420
499
 
421
500
  // module vars
@@ -558,7 +637,27 @@ class Retrier {
558
637
  return this
559
638
  }
560
639
  const newPolicy = new FixedIntervalPolicy(fixedInterval);
561
- oldPolicy?.copyPolicySetting(newPolicy);
640
+ oldPolicy?.copyPolicySettingTo(newPolicy);
641
+ newPolicy.reset();
642
+ this._policy = newPolicy;
643
+ return this
644
+ }
645
+
646
+ /**
647
+ * sets a fixed backoff strategy.
648
+ * @param {number} fixedInterval - The fixed interval between retries in milliseconds.
649
+ * @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
650
+ * @returns {Retrier} A retrier instance configured with fixed backoff.
651
+ */
652
+ fixedBackoff (fixedInterval, jitter = 500) {
653
+ const oldPolicy = this._policy;
654
+ if (oldPolicy instanceof FixedIntervalPolicy) {
655
+ oldPolicy.interval = fixedInterval;
656
+ oldPolicy.jitter = jitter;
657
+ return this
658
+ }
659
+ const newPolicy = new FixedBackoff(fixedInterval, jitter);
660
+ oldPolicy?.copyPolicySettingTo(newPolicy);
562
661
  newPolicy.reset();
563
662
  this._policy = newPolicy;
564
663
  return this
@@ -576,7 +675,27 @@ class Retrier {
576
675
  return this
577
676
  }
578
677
  const newPolicy = new FixedIncreasePolicy(increasement);
579
- oldPolicy?.copyPolicySetting(newPolicy);
678
+ oldPolicy?.copyPolicySettingTo(newPolicy);
679
+ newPolicy.reset();
680
+ this._policy = newPolicy;
681
+ return this
682
+ }
683
+
684
+ /**
685
+ * Sets a fixed increase policy for retry intervals.
686
+ * @param {number} increasement - The fixed amount to increase the interval by on each retry.
687
+ * @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
688
+ * @returns {this} The retrier instance for chaining.
689
+ */
690
+ linearBackoff (increasement, jitter = 500) {
691
+ const oldPolicy = this._policy;
692
+ if (oldPolicy instanceof LinearBackoff) {
693
+ oldPolicy.increasement = increasement;
694
+ oldPolicy.jitter = jitter;
695
+ return this
696
+ }
697
+ const newPolicy = new LinearBackoff(increasement, jitter);
698
+ oldPolicy?.copyPolicySettingTo(newPolicy);
580
699
  newPolicy.reset();
581
700
  this._policy = newPolicy;
582
701
  return this
@@ -594,7 +713,25 @@ class Retrier {
594
713
  return this
595
714
  }
596
715
  const newPolicy = new FactoreIncreasePolicy(factor);
597
- oldPolicy?.copyPolicySetting(newPolicy);
716
+ oldPolicy?.copyPolicySettingTo(newPolicy);
717
+ newPolicy.reset();
718
+ this._policy = newPolicy;
719
+ return this
720
+ }
721
+
722
+ /**
723
+ * Creates a new Retrier instance with exponential-backoff strategy.
724
+ * @param {number} [jitter]
725
+ * @returns {Retrier} A new Retrier instance
726
+ */
727
+ exponentialBackoff (jitter = 500) {
728
+ const oldPolicy = this._policy;
729
+ if (oldPolicy instanceof ExponentialBackoffPolicy) {
730
+ oldPolicy.jitter = jitter;
731
+ return this
732
+ }
733
+ const newPolicy = new ExponentialBackoffPolicy(jitter);
734
+ oldPolicy?.copyPolicySettingTo(newPolicy);
598
735
  newPolicy.reset();
599
736
  this._policy = newPolicy;
600
737
  return this
@@ -612,7 +749,7 @@ class Retrier {
612
749
  return this
613
750
  }
614
751
  const newPolicy = new ShuttlePolicy(stepLength);
615
- oldPolicy?.copyPolicySetting(newPolicy);
752
+ oldPolicy?.copyPolicySettingTo(newPolicy);
616
753
  newPolicy.reset();
617
754
  this._policy = newPolicy;
618
755
  return this
@@ -692,7 +829,7 @@ class Retrier {
692
829
  let lastError = null;
693
830
  // @ts-ignore
694
831
  this.emit(Event.Start, startAt);
695
- this._taskingFlag = A.defer();
832
+ this._taskingFlag = B.defer();
696
833
  let latency = null;
697
834
  while (true) {
698
835
  // need to stop?
@@ -719,10 +856,10 @@ class Retrier {
719
856
  // @ts-ignore
720
857
  this.emit(Event.Retry, this._currentRetries, latency);
721
858
  const task = this._task; // take task, it may be changed in events' callback functions
722
- const nextDelay = this._policy.generate();
859
+ const nextDelay = this._policy.generate(this._currentRetries);
723
860
  try {
724
861
  try {
725
- await A.timeout(task.execute(this._currentRetries, latency, nextDelay), this._taskTimeout, TaskTimoutFlag);
862
+ await B.timeout(task.execute(this._currentRetries, latency, nextDelay), this._taskTimeout, TaskTimoutFlag);
726
863
  } catch (err) {
727
864
  // @ts-ignore
728
865
  if (err.message === TaskTimoutFlag) {
@@ -763,7 +900,7 @@ class Retrier {
763
900
  this._taskingFlag.reject(lastError ?? new Error(`Max Retries Exceeded, Retring ${this._currentRetries} times > max ${this._maxRetries}`));
764
901
  break
765
902
  }
766
- await A.delay(nextDelay);
903
+ await B.delay(nextDelay);
767
904
  }
768
905
  this._taskingFlag.promise.finally(() => {
769
906
  this.resetRetryPolicy();
@@ -790,7 +927,7 @@ class Retrier {
790
927
  // @ts-ignore
791
928
  return this._breakFlag.promise
792
929
  }
793
- this._breakFlag = A.defer();
930
+ this._breakFlag = B.defer();
794
931
  this._breakReason = reason ?? new Error('Manually Stop');
795
932
  // @ts-ignore
796
933
  this.once(Event.Completed, () => {
@@ -1020,6 +1157,18 @@ function fixedInterval (fixedInterval) {
1020
1157
  return retrier
1021
1158
  }
1022
1159
 
1160
+ /**
1161
+ * Creates a retrier with a fixed backoff strategy.
1162
+ * @param {number} fixedInterval - The fixed interval between retries in milliseconds.
1163
+ * @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
1164
+ * @returns {Retrier} A retrier instance configured with fixed backoff.
1165
+ */
1166
+ function fixedBackoff (fixedInterval, jitter = 500) {
1167
+ const retrier = new Retrier();
1168
+ retrier.fixedBackoff(fixedInterval, jitter);
1169
+ return retrier
1170
+ }
1171
+
1023
1172
  /**
1024
1173
  * Creates a retrier with a fixed increase strategy.
1025
1174
  * @param {number} increasement - The fixed amount to increase on each retry.
@@ -1031,6 +1180,18 @@ function fixedIncrease (increasement) {
1031
1180
  return retrier
1032
1181
  }
1033
1182
 
1183
+ /**
1184
+ * Creates a retrier with a fixed increase strategy.
1185
+ * @param {number} increasement - The fixed amount to increase on each retry.
1186
+ * @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
1187
+ * @returns {Retrier} A retrier instance configured with fixed increase.
1188
+ */
1189
+ function linearBackoff (increasement, jitter = 500) {
1190
+ const retrier = new Retrier();
1191
+ retrier.linearBackoff(increasement, jitter);
1192
+ return retrier
1193
+ }
1194
+
1034
1195
  /**
1035
1196
  * Creates a new Retrier instance with factor-increase strategy.
1036
1197
  * @param {number} factor - The factor by which to increase the interval on each retry.
@@ -1042,6 +1203,17 @@ function factorIncrease (factor) {
1042
1203
  return retrier
1043
1204
  }
1044
1205
 
1206
+ /**
1207
+ * Creates a new Retrier instance with exponential-backoff strategy.
1208
+ * @param {number} [jitter=500]
1209
+ * @returns {Retrier} A new Retrier instance
1210
+ */
1211
+ function exponentialBackoff (jitter = 500) {
1212
+ const retrier = new Retrier();
1213
+ retrier.exponentialBackoff(jitter);
1214
+ return retrier
1215
+ }
1216
+
1045
1217
  /**
1046
1218
  * Creates a Retrier instance with a shuttle-interval strategt.
1047
1219
  * @param {number} stepLength - The interval step length of each change
@@ -1096,8 +1268,11 @@ var RetrierFactory = {
1096
1268
  max,
1097
1269
  range,
1098
1270
  fixedInterval,
1271
+ fixedBackoff,
1099
1272
  fixedIncrease,
1273
+ linearBackoff,
1100
1274
  factorIncrease,
1275
+ exponentialBackoff,
1101
1276
  shuttleInterval,
1102
1277
  timeout,
1103
1278
  taskTimeout,
@@ -1134,10 +1309,13 @@ exports.Policy = Policy;
1134
1309
  exports.Retrier = Retrier;
1135
1310
  exports.RetrierFactory = RetrierFactory;
1136
1311
  exports.default = index;
1312
+ exports.exponentialBackoff = exponentialBackoff;
1137
1313
  exports.factorIncrease = factorIncrease;
1314
+ exports.fixedBackoff = fixedBackoff;
1138
1315
  exports.fixedIncrease = fixedIncrease;
1139
1316
  exports.fixedInterval = fixedInterval;
1140
1317
  exports.infinite = infinite;
1318
+ exports.linearBackoff = linearBackoff;
1141
1319
  exports.max = max;
1142
1320
  exports.maxRetries = maxRetries;
1143
1321
  exports.min = min;