8000 [node-core-library] Provide `retryCount` parameter to actions execute… · OlliMartin/rushstack@c3f31d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit c3f31d2

Browse files
authored
[node-core-library] Provide retryCount parameter to actions executed using Async.runWithRetriesAsync (microsoft#5069)
* Add retryCount parameter to the action provided to Async.runWithRetriesAsync * Rush change --------- Co-authored-by: Daniel <D4N14L@users.noreply.github.com>
1 parent f2faa8c commit c3f31d2

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/node-core-library",
5+
"comment": "Provide the `retryCount` parameter to actions executed using `Async.runWithRetriesAsync`",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@rushstack/node-core-library"
10+
}

common/reviews/api/node-core-library.api.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,11 +616,8 @@ export interface IRealNodeModulePathResolverOptions {
616616

617617
// @public (undocumented)
618618
export interface IRunWithRetriesOptions<TResult> {
619-
// (undocumented)
620-
action: () => Promise<TResult> | TResult;
621-
// (undocumented)
619+
action: (retryCount: number) => Promise<TResult> | TResult;
622620
maxRetries: number;
623-
// (undocumented)
624621
retryDelayMs?: number;
625622
}
626623

libraries/node-core-library/src/Async.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,20 @@ export interface IAsyncParallelismOptions {
3232
* @public
3333
*/
3434
export interface IRunWithRetriesOptions<TResult> {
35-
action: () => Promise<TResult> | TResult;
35+
/**
36+
* The action to be performed. The action is repeatedly executed until it completes without throwing or the
37+
* maximum number of retries is reached.
38+
*
39+
* @param retryCount - The number of times the action has been retried.
40+
*/
41+
action: (retryCount: number) => Promise<TResult> | TResult;
42+
/**
43+
* The maximum number of times the action should be retried.
44+
*/
3645
maxRetries: number;
46+
/**
47+
* The delay in milliseconds between retries.
48+
*/
3749
retryDelayMs?: number;
3850
}
3951

@@ -313,13 +325,13 @@ export class Async {
313325
maxRetries,
314326
retryDelayMs = 0
315327
}: IRunWithRetriesOptions<TResult>): Promise<TResult> {
316-
let retryCounter: number = 0;
328+
let retryCount: number = 0;
317329
// eslint-disable-next-line no-constant-condition
318330
while (true) {
319331
try {
320-
return await action();
332+
return await action(retryCount);
321333
} catch (e) {
322-
if (++retryCounter > maxRetries) {
334+
if (++retryCount > maxRetries) {
323335
throw e;
324336
} else if (retryDelayMs > 0) {
325337
await Async.sleepAsync(retryDelayMs);

0 commit comments

Comments
 (0)
0