@augment-vir/common 21.4.0 → 21.5.0
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,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.callAsynchronously = exports.wrapPromiseInTimeout = exports.PromiseTimeoutError = exports.isPromiseLike = void 0;
|
|
3
|
+
exports.executeWithRetries = exports.callAsynchronously = exports.wrapPromiseInTimeout = exports.PromiseTimeoutError = exports.isPromiseLike = void 0;
|
|
4
4
|
const typed_has_property_1 = require("../object/typed-has-property");
|
|
5
5
|
function isPromiseLike(input) {
|
|
6
6
|
if ((0, typed_has_property_1.typedHasProperty)(input, 'then') && typeof input.then === 'function') {
|
|
@@ -48,3 +48,17 @@ async function callAsynchronously(callback) {
|
|
|
48
48
|
return await Promise.resolve().then(() => callback());
|
|
49
49
|
}
|
|
50
50
|
exports.callAsynchronously = callAsynchronously;
|
|
51
|
+
async function executeWithRetries(retryCount, callback) {
|
|
52
|
+
let currentRetry = 0;
|
|
53
|
+
while (currentRetry < retryCount) {
|
|
54
|
+
try {
|
|
55
|
+
const result = await callback();
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
currentRetry++;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
throw new Error('Retry max reached.');
|
|
63
|
+
}
|
|
64
|
+
exports.executeWithRetries = executeWithRetries;
|
|
@@ -41,3 +41,16 @@ export function wrapPromiseInTimeout(durationMs, originalPromise) {
|
|
|
41
41
|
export async function callAsynchronously(callback) {
|
|
42
42
|
return await Promise.resolve().then(() => callback());
|
|
43
43
|
}
|
|
44
|
+
export async function executeWithRetries(retryCount, callback) {
|
|
45
|
+
let currentRetry = 0;
|
|
46
|
+
while (currentRetry < retryCount) {
|
|
47
|
+
try {
|
|
48
|
+
const result = await callback();
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
currentRetry++;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
throw new Error('Retry max reached.');
|
|
56
|
+
}
|
|
@@ -12,3 +12,4 @@ export declare function wrapPromiseInTimeout<PromiseValueType>(durationMs: numbe
|
|
|
12
12
|
* function was originally synchronous.
|
|
13
13
|
*/
|
|
14
14
|
export declare function callAsynchronously<T>(callback: () => MaybePromise<T>): Promise<T>;
|
|
15
|
+
export declare function executeWithRetries<T>(retryCount: number, callback: () => T): Promise<T>;
|