File tree Expand file tree Collapse file tree 3 files changed +27
-8
lines changed
changes/@rushstack/node-core-library
libraries/node-core-library/src Expand file tree Collapse file tree 3 files changed +27
-8
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -616,11 +616,8 @@ export interface IRealNodeModulePathResolverOptions {
616
616
617
617
// @public (undocumented)
618
618
export interface IRunWithRetriesOptions <TResult > {
619
- // (undocumented)
620
- action: () => Promise <TResult > | TResult ;
621
- // (undocumented)
619
+ action: (retryCount : number ) => Promise <TResult > | TResult ;
622
620
maxRetries: number ;
623
- // (undocumented)
624
621
retryDelayMs? : number ;
625
622
}
626
623
Original file line number Diff line number Diff line change @@ -32,8 +32,20 @@ export interface IAsyncParallelismOptions {
32
32
* @public
33
33
*/
34
34
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
+ */
36
45
maxRetries : number ;
46
+ /**
47
+ * The delay in milliseconds between retries.
48
+ */
37
49
retryDelayMs ?: number ;
38
50
}
39
51
@@ -313,13 +325,13 @@ export class Async {
313
325
maxRetries,
314
326
retryDelayMs = 0
315
327
} : IRunWithRetriesOptions < TResult > ) : Promise < TResult > {
316
- let retryCounter : number = 0 ;
328
+ let retryCount : number = 0 ;
317
329
// eslint-disable-next-line no-constant-condition
318
330
while ( true ) {
319
331
try {
320
- return await action ( ) ;
332
+ return await action ( retryCount ) ;
321
333
} catch ( e ) {
322
- if ( ++ retryCounter > maxRetries ) {
334
+ if ( ++ retryCount > maxRetries ) {
323
335
throw e ;
324
336
} else if ( retryDelayMs > 0 ) {
325
337
await Async . sleepAsync ( retryDelayMs ) ;
You can’t perform that action at this time.
0 commit comments