@rushstack/node-core-library
Advanced tools
Comparing version 3.49.0 to 3.50.0
@@ -17,2 +17,13 @@ /** | ||
/** | ||
* @remarks | ||
* Used with {@link Async.runWithRetriesAsync}. | ||
* | ||
* @beta | ||
*/ | ||
export interface IRunWithRetriesOptions<TResult> { | ||
action: () => Promise<TResult> | TResult; | ||
maxRetries: number; | ||
retryDelayMs?: number; | ||
} | ||
/** | ||
* Utilities for parallel asynchronous operations, for use with the system `Promise` APIs. | ||
@@ -67,3 +78,7 @@ * | ||
static sleep(ms: number): Promise<void>; | ||
/** | ||
* Executes an async function and optionally retries it if it fails. | ||
*/ | ||
static runWithRetriesAsync<TResult>({ action, maxRetries, retryDelayMs }: IRunWithRetriesOptions<TResult>): Promise<TResult>; | ||
} | ||
//# sourceMappingURL=Async.d.ts.map |
@@ -119,4 +119,24 @@ "use strict"; | ||
} | ||
/** | ||
* Executes an async function and optionally retries it if it fails. | ||
*/ | ||
static async runWithRetriesAsync({ action, maxRetries, retryDelayMs = 0 }) { | ||
let retryCounter = 0; | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
try { | ||
return await action(); | ||
} | ||
catch (e) { | ||
if (++retryCounter > maxRetries) { | ||
throw e; | ||
} | ||
else if (retryDelayMs > 0) { | ||
await Async.sleep(retryDelayMs); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
exports.Async = Async; | ||
//# sourceMappingURL=Async.js.map |
@@ -8,3 +8,3 @@ /** | ||
export { AnsiEscape, IAnsiEscapeConvertForTestsOptions } from './Terminal/AnsiEscape'; | ||
export { Async, IAsyncParallelismOptions } from './Async'; | ||
export { Async, IAsyncParallelismOptions, IRunWithRetriesOptions } from './Async'; | ||
export { Brand } from './PrimitiveTypes'; | ||
@@ -11,0 +11,0 @@ export { FileConstants, FolderConstants } from './Constants'; |
{ | ||
"name": "@rushstack/node-core-library", | ||
"version": "3.49.0", | ||
"version": "3.50.0", | ||
"description": "Core libraries that every NodeJS toolchain project should use", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1010218
13264