Skip to content

Commit

Permalink
Add retry example to Tips readme section (#386)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
justsml and sindresorhus committed Nov 8, 2019
1 parent 2956ea1 commit ecdbad3
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions readme.md
Expand Up @@ -532,6 +532,23 @@ List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the

## Tips

### Retry on error

Gracefully handle failures by using automatic retries and exponential backoff with the [`p-retry`](https://github.com/sindresorhus/p-retry) package:

```js
const pRetry = require('p-retry');

const run = async () => {
const results = await execa('curl', ['-sSL', 'https://sindresorhus.com/unicorn']);
return results;
};

(async () => {
console.log(await pRetry(run, {retries: 5}));
})();
```

### Save and pipe output from a child process

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

0 comments on commit ecdbad3

Please sign in to comment.