Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | 2x 2x 2x 2x | const wait = ms => new Promise(r => setTimeout(r, ms)); const retryPromise = (operation, delay, times) => new Promise((resolve, reject) => { return operation() .then(resolve) .catch((reason) => { if (times - 1 > 0) { console.log("Retry to connect to mongodb...") return wait(delay) .then(retryPromise.bind(null, operation, delay, times - 1)) .then(resolve) .catch(reject); } return reject(reason); }); }); module.exports = { retryPromise }; |