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.
45 function 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 }
2 export 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 }