@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.
@@ -1,4 +1,4 @@
1
- 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)}}
1
+ 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)}}
2
2
 
3
3
  // module vars
4
4
  const DefaultMinInterval = 50;
@@ -8,7 +8,7 @@ const DefaultMaxRetries = 3;
8
8
  // internal
9
9
 
10
10
  // module vars
11
- const { assertPositive: assertPositive$5 } = b$1;
11
+ const { assertPositive: assertPositive$5, assertNotNegative: assertNotNegative$3 } = b$1;
12
12
  const { isNumber } = r$1;
13
13
 
14
14
  class Policy {
@@ -19,13 +19,25 @@ class Policy {
19
19
  this._min = DefaultMinInterval;
20
20
  this._max = DefaultMaxInterval;
21
21
  this._nextInterval = this._min;
22
+ this._jitter = 0;
23
+ }
24
+
25
+ get jitter () {
26
+ return this._jitter
27
+ }
28
+
29
+ set jitter (jitter) {
30
+ assertNotNegative$3(jitter, 'jitter');
31
+ this._jitter = jitter;
22
32
  }
23
33
 
24
34
  /**
25
35
  * Copies settings to target policy.
36
+ * 1. range
37
+ * 2. nextInterval value
26
38
  * @param {Policy} targetPolicy - The policy to modify.
27
39
  */
28
- copyPolicySetting (targetPolicy) {
40
+ copyPolicySettingTo (targetPolicy) {
29
41
  targetPolicy.range(this._min, this._max);
30
42
  targetPolicy._nextInterval = this._nextInterval;
31
43
  }
@@ -100,20 +112,25 @@ class Policy {
100
112
 
101
113
  /**
102
114
  * Interval ms of next execution
115
+ * @param {number} retries current retry times
103
116
  * @returns {number}
104
- * @throws {Error} Always throws "Not Implemented Yet" error.
105
117
  */
106
- generate () {
118
+ generate (retries) {
107
119
  const rtnVal = this._nextInterval;
108
- this._increase();
120
+ this._increase(retries);
109
121
  return rtnVal
110
122
  }
111
123
 
112
- _increase () {
113
- const nextInterval = this._next();
114
- if (!isNumber(nextInterval)) {
124
+ /**
125
+ * @param {number} retries current retry times
126
+ * @returns {number}
127
+ */
128
+ _increase (retries) {
129
+ const generated = this._next(retries);
130
+ if (!isNumber(generated)) {
115
131
  throw new Error('Generated Next Interval Not Number')
116
132
  }
133
+ const nextInterval = this._jitter <= 0 ? generated : generated + Math.floor(Math.random() * this._jitter);
117
134
  if (nextInterval < this._min) {
118
135
  return (this._nextInterval = this._min)
119
136
  } else if (nextInterval > this._max) {
@@ -124,10 +141,11 @@ class Policy {
124
141
 
125
142
  /**
126
143
  * subclass should implement this method
144
+ * @param {number} retries current retry times
127
145
  * @returns {number} The interval in milliseconds to wait before the next retry attempt.
128
146
  * @protected
129
147
  */
130
- _next () {
148
+ _next (retries) {
131
149
  throw new Error('Not Impled Yet')
132
150
  }
133
151
  }
@@ -182,10 +200,11 @@ class FixedIntervalPolicy extends Policy {
182
200
 
183
201
  /**
184
202
  * Interval ms of next execution
203
+ * @param {number} retries
185
204
  * @returns {number}
186
205
  * @throws {Error} Always throws "Not Implemented Yet" error.
187
206
  */
188
- _next () {
207
+ _next (retries) {
189
208
  return this.interval
190
209
  }
191
210
  }
@@ -216,9 +235,10 @@ class FixedIncreasePolicy extends Policy {
216
235
 
217
236
  /**
218
237
  * Interval ms of next execution
238
+ * @param {number} retries
219
239
  * @returns {number}
220
240
  */
221
- _next () {
241
+ _next (retries) {
222
242
  if (this._nextInterval >= this._max) {
223
243
  return this._max
224
244
  }
@@ -259,9 +279,10 @@ class FactoreIncreasePolicy extends Policy {
259
279
 
260
280
  /**
261
281
  * Interval ms of next execution
282
+ * @param {number} retries
262
283
  * @returns {number}
263
284
  */
264
- _next () {
285
+ _next (retries) {
265
286
  if (this._nextInterval >= this._max) {
266
287
  return this._max
267
288
  }
@@ -298,10 +319,11 @@ class ShuttlePolicy extends Policy {
298
319
 
299
320
  /**
300
321
  * Interval ms of next execution
322
+ * @param {number} retries
301
323
  * @returns {number}
302
324
  * @throws {Error} Always throws "Not Implemented Yet" error.
303
325
  */
304
- _next () {
326
+ _next (retries) {
305
327
  const nextInterval = this._nextInterval + this.increasement;
306
328
  if (nextInterval >= this._max) {
307
329
  this.increasement = -this.stepLength;
@@ -412,6 +434,63 @@ class AlwaysTask extends Task {
412
434
  }
413
435
  }
414
436
 
437
+ // internal
438
+ // module vars
439
+ const { assertNotNegative: assertNotNegative$2 } = b$1;
440
+ /**
441
+ * @class FixedBackoff
442
+ */
443
+ class FixedBackoff extends FixedIntervalPolicy {
444
+ /**
445
+ * Creates a fixed backoff policy with optional jitter.
446
+ * @param {number} fixedInterval - The fixed interval between retries in milliseconds.
447
+ * @param {number} [jitter=500] - The maximum random jitter to add to the interval in milliseconds.
448
+ */
449
+ constructor (fixedInterval, jitter = 500) {
450
+ super(fixedInterval);
451
+ assertNotNegative$2(jitter, 'jitter');
452
+ this._jitter = jitter ?? 500;
453
+ }
454
+ }
455
+
456
+ // internal
457
+
458
+ // module vars
459
+ const { assertNotNegative: assertNotNegative$1 } = b$1;
460
+ /**
461
+ * @class ExponentialBackoffPolicy
462
+ */
463
+ class ExponentialBackoffPolicy extends FactoreIncreasePolicy {
464
+ /**
465
+ * Creates an exponential backoff policy with optional jitter.
466
+ * @param {number} [jitter=500] - Maximum jitter in milliseconds to add to backoff intervals.
467
+ */
468
+ constructor (jitter = 500) {
469
+ super(2);
470
+ assertNotNegative$1(jitter, 'jitter');
471
+ this._jitter = jitter ?? 500;
472
+ }
473
+ }
474
+
475
+ // internal
476
+ // module vars
477
+ const { assertNotNegative } = b$1;
478
+ /**
479
+ * @class LinearBackoff
480
+ */
481
+ class LinearBackoff extends FixedIncreasePolicy {
482
+ /**
483
+ * Creates a linear backoff policy with optional jitter.
484
+ * @param {number} increasement - The base increasement value for backoff.
485
+ * @param {number} [jitter=500] - The maximum jitter value to add to backoff (default: 500).
486
+ */
487
+ constructor (increasement, jitter = 500) {
488
+ super(increasement);
489
+ assertNotNegative(jitter, 'jitter');
490
+ this._jitter = jitter ?? 500;
491
+ }
492
+ }
493
+
415
494
  // internal
416
495
 
417
496
  // module vars
@@ -554,7 +633,27 @@ class Retrier {
554
633
  return this
555
634
  }
556
635
  const newPolicy = new FixedIntervalPolicy(fixedInterval);
557
- oldPolicy?.copyPolicySetting(newPolicy);
636
+ oldPolicy?.copyPolicySettingTo(newPolicy);
637
+ newPolicy.reset();
638
+ this._policy = newPolicy;
639
+ return this
640
+ }
641
+
642
+ /**
643
+ * sets a fixed backoff strategy.
644
+ * @param {number} fixedInterval - The fixed interval between retries in milliseconds.
645
+ * @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
646
+ * @returns {Retrier} A retrier instance configured with fixed backoff.
647
+ */
648
+ fixedBackoff (fixedInterval, jitter = 500) {
649
+ const oldPolicy = this._policy;
650
+ if (oldPolicy instanceof FixedIntervalPolicy) {
651
+ oldPolicy.interval = fixedInterval;
652
+ oldPolicy.jitter = jitter;
653
+ return this
654
+ }
655
+ const newPolicy = new FixedBackoff(fixedInterval, jitter);
656
+ oldPolicy?.copyPolicySettingTo(newPolicy);
558
657
  newPolicy.reset();
559
658
  this._policy = newPolicy;
560
659
  return this
@@ -572,7 +671,27 @@ class Retrier {
572
671
  return this
573
672
  }
574
673
  const newPolicy = new FixedIncreasePolicy(increasement);
575
- oldPolicy?.copyPolicySetting(newPolicy);
674
+ oldPolicy?.copyPolicySettingTo(newPolicy);
675
+ newPolicy.reset();
676
+ this._policy = newPolicy;
677
+ return this
678
+ }
679
+
680
+ /**
681
+ * Sets a fixed increase policy for retry intervals.
682
+ * @param {number} increasement - The fixed amount to increase the interval by on each retry.
683
+ * @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
684
+ * @returns {this} The retrier instance for chaining.
685
+ */
686
+ linearBackoff (increasement, jitter = 500) {
687
+ const oldPolicy = this._policy;
688
+ if (oldPolicy instanceof LinearBackoff) {
689
+ oldPolicy.increasement = increasement;
690
+ oldPolicy.jitter = jitter;
691
+ return this
692
+ }
693
+ const newPolicy = new LinearBackoff(increasement, jitter);
694
+ oldPolicy?.copyPolicySettingTo(newPolicy);
576
695
  newPolicy.reset();
577
696
  this._policy = newPolicy;
578
697
  return this
@@ -590,7 +709,25 @@ class Retrier {
590
709
  return this
591
710
  }
592
711
  const newPolicy = new FactoreIncreasePolicy(factor);
593
- oldPolicy?.copyPolicySetting(newPolicy);
712
+ oldPolicy?.copyPolicySettingTo(newPolicy);
713
+ newPolicy.reset();
714
+ this._policy = newPolicy;
715
+ return this
716
+ }
717
+
718
+ /**
719
+ * Creates a new Retrier instance with exponential-backoff strategy.
720
+ * @param {number} [jitter]
721
+ * @returns {Retrier} A new Retrier instance
722
+ */
723
+ exponentialBackoff (jitter = 500) {
724
+ const oldPolicy = this._policy;
725
+ if (oldPolicy instanceof ExponentialBackoffPolicy) {
726
+ oldPolicy.jitter = jitter;
727
+ return this
728
+ }
729
+ const newPolicy = new ExponentialBackoffPolicy(jitter);
730
+ oldPolicy?.copyPolicySettingTo(newPolicy);
594
731
  newPolicy.reset();
595
732
  this._policy = newPolicy;
596
733
  return this
@@ -608,7 +745,7 @@ class Retrier {
608
745
  return this
609
746
  }
610
747
  const newPolicy = new ShuttlePolicy(stepLength);
611
- oldPolicy?.copyPolicySetting(newPolicy);
748
+ oldPolicy?.copyPolicySettingTo(newPolicy);
612
749
  newPolicy.reset();
613
750
  this._policy = newPolicy;
614
751
  return this
@@ -688,7 +825,7 @@ class Retrier {
688
825
  let lastError = null;
689
826
  // @ts-ignore
690
827
  this.emit(Event.Start, startAt);
691
- this._taskingFlag = A.defer();
828
+ this._taskingFlag = B.defer();
692
829
  let latency = null;
693
830
  while (true) {
694
831
  // need to stop?
@@ -715,10 +852,10 @@ class Retrier {
715
852
  // @ts-ignore
716
853
  this.emit(Event.Retry, this._currentRetries, latency);
717
854
  const task = this._task; // take task, it may be changed in events' callback functions
718
- const nextDelay = this._policy.generate();
855
+ const nextDelay = this._policy.generate(this._currentRetries);
719
856
  try {
720
857
  try {
721
- await A.timeout(task.execute(this._currentRetries, latency, nextDelay), this._taskTimeout, TaskTimoutFlag);
858
+ await B.timeout(task.execute(this._currentRetries, latency, nextDelay), this._taskTimeout, TaskTimoutFlag);
722
859
  } catch (err) {
723
860
  // @ts-ignore
724
861
  if (err.message === TaskTimoutFlag) {
@@ -759,7 +896,7 @@ class Retrier {
759
896
  this._taskingFlag.reject(lastError ?? new Error(`Max Retries Exceeded, Retring ${this._currentRetries} times > max ${this._maxRetries}`));
760
897
  break
761
898
  }
762
- await A.delay(nextDelay);
899
+ await B.delay(nextDelay);
763
900
  }
764
901
  this._taskingFlag.promise.finally(() => {
765
902
  this.resetRetryPolicy();
@@ -786,7 +923,7 @@ class Retrier {
786
923
  // @ts-ignore
787
924
  return this._breakFlag.promise
788
925
  }
789
- this._breakFlag = A.defer();
926
+ this._breakFlag = B.defer();
790
927
  this._breakReason = reason ?? new Error('Manually Stop');
791
928
  // @ts-ignore
792
929
  this.once(Event.Completed, () => {
@@ -1016,6 +1153,18 @@ function fixedInterval (fixedInterval) {
1016
1153
  return retrier
1017
1154
  }
1018
1155
 
1156
+ /**
1157
+ * Creates a retrier with a fixed backoff strategy.
1158
+ * @param {number} fixedInterval - The fixed interval between retries in milliseconds.
1159
+ * @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
1160
+ * @returns {Retrier} A retrier instance configured with fixed backoff.
1161
+ */
1162
+ function fixedBackoff (fixedInterval, jitter = 500) {
1163
+ const retrier = new Retrier();
1164
+ retrier.fixedBackoff(fixedInterval, jitter);
1165
+ return retrier
1166
+ }
1167
+
1019
1168
  /**
1020
1169
  * Creates a retrier with a fixed increase strategy.
1021
1170
  * @param {number} increasement - The fixed amount to increase on each retry.
@@ -1027,6 +1176,18 @@ function fixedIncrease (increasement) {
1027
1176
  return retrier
1028
1177
  }
1029
1178
 
1179
+ /**
1180
+ * Creates a retrier with a fixed increase strategy.
1181
+ * @param {number} increasement - The fixed amount to increase on each retry.
1182
+ * @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
1183
+ * @returns {Retrier} A retrier instance configured with fixed increase.
1184
+ */
1185
+ function linearBackoff (increasement, jitter = 500) {
1186
+ const retrier = new Retrier();
1187
+ retrier.linearBackoff(increasement, jitter);
1188
+ return retrier
1189
+ }
1190
+
1030
1191
  /**
1031
1192
  * Creates a new Retrier instance with factor-increase strategy.
1032
1193
  * @param {number} factor - The factor by which to increase the interval on each retry.
@@ -1038,6 +1199,17 @@ function factorIncrease (factor) {
1038
1199
  return retrier
1039
1200
  }
1040
1201
 
1202
+ /**
1203
+ * Creates a new Retrier instance with exponential-backoff strategy.
1204
+ * @param {number} [jitter=500]
1205
+ * @returns {Retrier} A new Retrier instance
1206
+ */
1207
+ function exponentialBackoff (jitter = 500) {
1208
+ const retrier = new Retrier();
1209
+ retrier.exponentialBackoff(jitter);
1210
+ return retrier
1211
+ }
1212
+
1041
1213
  /**
1042
1214
  * Creates a Retrier instance with a shuttle-interval strategt.
1043
1215
  * @param {number} stepLength - The interval step length of each change
@@ -1092,8 +1264,11 @@ var RetrierFactory = {
1092
1264
  max,
1093
1265
  range,
1094
1266
  fixedInterval,
1267
+ fixedBackoff,
1095
1268
  fixedIncrease,
1269
+ linearBackoff,
1096
1270
  factorIncrease,
1271
+ exponentialBackoff,
1097
1272
  shuttleInterval,
1098
1273
  timeout,
1099
1274
  taskTimeout,
@@ -1125,5 +1300,5 @@ var index = {
1125
1300
  ...RetrierFactory
1126
1301
  };
1127
1302
 
1128
- export { Event, Policy, Retrier, RetrierFactory, index as default, factorIncrease, fixedIncrease, fixedInterval, infinite, max, maxRetries, min, name, range, shuttleInterval, start, taskTimeout, timeout, times };
1303
+ export { Event, Policy, Retrier, RetrierFactory, index as default, exponentialBackoff, factorIncrease, fixedBackoff, fixedIncrease, fixedInterval, infinite, linearBackoff, max, maxRetries, min, name, range, shuttleInterval, start, taskTimeout, timeout, times };
1129
1304
  //# sourceMappingURL=index-dev.js.map