Skip to content
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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Owner

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.

*
@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

View workflow job for this annotation

GitHub Actions / Node.js 20

Mixed spaces and tabs.

Check failure on line 105 in index.d.ts

View workflow job for this annotation

GitHub Actions / Node.js 18

Mixed spaces and tabs.

Check failure on line 105 in index.d.ts

View workflow job for this annotation

GitHub Actions / Node.js 16

Mixed spaces and tabs.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The option is coming from the retry package, so this needs to be added to @types/retry.

} & OperationOptions;

/**
Expand Down
5 changes: 5 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ expectType<Promise<string>>(
retries: 5,
}),
);
expectType<Promise<string>>(
pRetry(() => 'foo', {
randomize: true,
}),
);

const abortError = new AbortError('foo');
new AbortError(new Error('foo')); // eslint-disable-line no-new
Expand Down
17 changes: 17 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already covered by:

Options are passed to the retry module.



### AbortError(message)
### AbortError(error)

Expand Down
Loading