-
-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Add randomize option #77
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,24 @@ | |
``` | ||
*/ | ||
readonly signal?: AbortSignal; | ||
|
||
/** | ||
Decide if a random delay should be introduced between retries. | ||
Enabling this option adds variability to the retry strategy, helping to distribute load peaks and reduce contention. | ||
If set to `true`, a random delay will be introduced between each retry attempt. | ||
* | ||
@example | ||
``` | ||
import pRetry from 'p-retry'; | ||
* | ||
const run = async () => { ... }; | ||
* | ||
const result = await pRetry(run, { | ||
randomize: true | ||
}); | ||
``` | ||
*/ | ||
readonly randomize?: boolean; | ||
Check failure on line 105 in index.d.ts GitHub Actions / Node.js 20
Check failure on line 105 in index.d.ts GitHub Actions / Node.js 18
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The option is coming from the |
||
} & OperationOptions; | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,23 @@ try { | |
} | ||
``` | ||
|
||
##### randomize | ||
|
||
Decide whether to introduce a random delay between retry attempts. (multiply with a factor between 1 to 2) | ||
|
||
Enabling this option adds variability to the retry strategy, helping to distribute load peaks and reduce contention among concurrent retry attempts. | ||
|
||
```js | ||
import pRetry from 'p-retry'; | ||
|
||
const run = async () => { … }; | ||
|
||
const result = await pRetry(run, { | ||
randomize: true | ||
}); | ||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already covered by:
|
||
|
||
|
||
### AbortError(message) | ||
### AbortError(error) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needs to say what the random delay range could be.