How to use 'p-retry' in JavaScript

Every line of 'p-retry' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
45function retry (n) {
46 if (n <= 0) {
47 reject('Invocation failed. No retries left.');
48 } else {
49 wsk.actions
50 .invoke({
51 actionName: actionName,
52 params: args,
53 blocking: true
54 })
55 .then(activation => resolve(activation.response.result) )
56 .catch(error => {
57 console.log(`attempt ${n} failed, retrying`);
58 retry(n - 1);
59 });
60 }
61}
2export function retry(func, retryCount = 5) {
3 return new Promise((resolve, reject) => {
4 func().then(
5 (...args) => {
6 resolve(...args);
7 },
8 () => {
9 if (retryCount === 0) {
10 return reject();
11 }
12 return setTimeout(() => retry(func, retryCount - 1).then(resolve, reject), 50);
13 },
14 );
15 });
16}

Related snippets