We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hi, I wrote an higher-level function util withRetry which makes the usage of the library very easy and also supports promises.
withRetry
this is what I wrote:
const retry = require('retry'); function withRetry(callback) { return (...args) => { const operation = retry.operation({ retries: 5 }); return new Promise((resolve, reject) => { operation.attempt(async function (currentAttempt) { try { const result = await callback(...args); resolve(result); } catch (err) { console.log(`attempt #${currentAttempt} failed. error: ${err.message}`); if (operation.retry(err)) { return; } reject(err); } }); }); }; } module.exports = withRetry;
now any function could be enhanced with retry logic using a single line. e.g:
async functuin myFunc(a, b) { // .. bla bla async logic .. return a + b } module.exports = withRetry(myFunc);
if it feels useful, I can make the code more generic, and contribute as PR
The text was updated successfully, but these errors were encountered:
isn't that already mostly done with wrap function, although different signature?
wrap
Sorry, something went wrong.
No branches or pull requests
Hi, I wrote an higher-level function util
withRetry
which makes the usage of the library very easy and also supports promises.this is what I wrote:
now any function could be enhanced with retry logic using a single line. e.g:
if it feels useful, I can make the code more generic, and contribute as PR
The text was updated successfully, but these errors were encountered: