From 18904b3dba839349b655f4ec16116f349d78ad05 Mon Sep 17 00:00:00 2001 From: Dan Levy Date: Sat, 2 Nov 2019 17:20:15 -0600 Subject: [PATCH 1/6] adresses or fixes #362 --- readme.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/readme.md b/readme.md index 18f5099318..b627e52241 100644 --- a/readme.md +++ b/readme.md @@ -508,6 +508,29 @@ List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the ## Tips +### Retry on Error + +Retry on system errors `EAGAIN` or `ETIMEDOUT`. + +```js +const promiseRetry = require('promise-retry'); + +(async () => { + const results = await promiseRetry(function (retry, number) { + + try { + await execa('node', ['--version']); + } catch (error) { + if (number > 10) throw new Error('Execution retry limit of 10 exceeded.'); + + if (error.code === 'EAGAIN' || error.code === 'ETIMEDOUT') { + retry(err); + } + } + }); +}); +``` + ### 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. From ebd99a0eba45b6624f36c56407d09968c496e133 Mon Sep 17 00:00:00 2001 From: Dan Levy Date: Sat, 2 Nov 2019 17:24:17 -0600 Subject: [PATCH 2/6] fixes missing "async" --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index b627e52241..4d96d81a8d 100644 --- a/readme.md +++ b/readme.md @@ -516,7 +516,7 @@ Retry on system errors `EAGAIN` or `ETIMEDOUT`. const promiseRetry = require('promise-retry'); (async () => { - const results = await promiseRetry(function (retry, number) { + const results = await promiseRetry(async (retry, number) => { try { await execa('node', ['--version']); From 9c3c50855d9a6764a0a9d9ea748cc35a348d70ff Mon Sep 17 00:00:00 2001 From: Dan Levy <397632+justsml@users.noreply.github.com> Date: Sun, 3 Nov 2019 15:35:01 -0700 Subject: [PATCH 3/6] Update readme.md --- readme.md | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/readme.md b/readme.md index 4d96d81a8d..662daf3e2a 100644 --- a/readme.md +++ b/readme.md @@ -510,25 +510,19 @@ List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the ### Retry on Error -Retry on system errors `EAGAIN` or `ETIMEDOUT`. +Handle failures with automatic retries & exponential backoff using the [`p-retry`](https://github.com/sindresorhus/p-retry) library. ```js -const promiseRetry = require('promise-retry'); - -(async () => { - const results = await promiseRetry(async (retry, number) => { +const pRetry = require('p-retry'); - try { - await execa('node', ['--version']); - } catch (error) { - if (number > 10) throw new Error('Execution retry limit of 10 exceeded.'); +const run = async () => { + const results = await execa('curl', ['-sSL', 'https://sindresorhus.com/unicorn']); + return results; +}; - if (error.code === 'EAGAIN' || error.code === 'ETIMEDOUT') { - retry(err); - } - } - }); -}); +(async () => { + console.log(await pRetry(run, {retries: 5})); +})(); ``` ### Save and pipe output from a child process From 745fac5bf0c044e617a5866bd85beeb37108fe47 Mon Sep 17 00:00:00 2001 From: Dan Levy <397632+justsml@users.noreply.github.com> Date: Thu, 7 Nov 2019 19:57:22 -0700 Subject: [PATCH 4/6] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 662daf3e2a..3e855cb95f 100644 --- a/readme.md +++ b/readme.md @@ -508,7 +508,7 @@ List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the ## Tips -### Retry on Error +### Retry on error Handle failures with automatic retries & exponential backoff using the [`p-retry`](https://github.com/sindresorhus/p-retry) library. From 2e5483e39837a74be5f8f7eacaf07d66d76ef056 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 9 Nov 2019 03:04:02 +0700 Subject: [PATCH 5/6] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 3e855cb95f..04ebe3217f 100644 --- a/readme.md +++ b/readme.md @@ -510,7 +510,7 @@ List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the ### Retry on error -Handle failures with automatic retries & exponential backoff using the [`p-retry`](https://github.com/sindresorhus/p-retry) library. +Gracefully handle failures with automatic retries and exponential backoff using the [`p-retry`](https://github.com/sindresorhus/p-retry) package: ```js const pRetry = require('p-retry'); From 25fc9d1100a1327548ff14d3ba18a11d2bab24e5 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 9 Nov 2019 03:05:09 +0700 Subject: [PATCH 6/6] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 04ebe3217f..614fbb1877 100644 --- a/readme.md +++ b/readme.md @@ -510,7 +510,7 @@ List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the ### Retry on error -Gracefully handle failures with automatic retries and exponential backoff using the [`p-retry`](https://github.com/sindresorhus/p-retry) package: +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');