Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus authored Dec 20, 2023
1 parent e01e03e commit 4fb170e
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,31 +110,11 @@ It is not called for `TypeError` (except network errors) and `AbortError`.
```js
import pRetry from 'p-retry';

const run = async () => {
const response = await fetch('https://sindresorhus.com/unicorn');

if (!response.ok) {
throw new Error(response.statusText);
}

return response.json();
};

const startTime = new Date();
const run = async () => { … };

const result = await pRetry(run, {
shouldRetry: (error) => {
const elapsedTime = new Date() - startTime;
if (elapsedTime < 1000) {
return true;
}
console.log(`Attempt ${error.attemptCount} failed.`);
return false;
},
retries: 30
shouldRetry: error => !(error instanceof CustomError);
});

console.log(result);
```

##### signal
Expand Down

0 comments on commit 4fb170e

Please sign in to comment.