Skip to content

Commit ecdbad3

Browse files
justsmlsindresorhus
andcommitted
Add retry example to Tips readme section (#386)
Co-authored-by: Sindre Sorhus <[email protected]>
1 parent 2956ea1 commit ecdbad3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

readme.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,23 @@ List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the
532532

533533
## Tips
534534

535+
### Retry on error
536+
537+
Gracefully handle failures by using automatic retries and exponential backoff with the [`p-retry`](https://github.com/sindresorhus/p-retry) package:
538+
539+
```js
540+
const pRetry = require('p-retry');
541+
542+
const run = async () => {
543+
const results = await execa('curl', ['-sSL', 'https://sindresorhus.com/unicorn']);
544+
return results;
545+
};
546+
547+
(async () => {
548+
console.log(await pRetry(run, {retries: 5}));
549+
})();
550+
```
551+
535552
### Save and pipe output from a child process
536553

537554
Let's say you want to show the output of a child process in real-time while also saving it to a variable.

0 commit comments

Comments
 (0)