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

Add retry example to Tips readme section #386

Merged
merged 6 commits into from Nov 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions readme.md
Expand Up @@ -508,6 +508,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