@alexknips/nestjs-kafka-events
Version:
Lightweight, tested, straight-forward wrapper around KafkaJS and Confluent's Schema Registry.
24 lines • 930 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.retry = void 0;
const waitFor = (seconds) => new Promise((r) => { var _a; return setTimeout(r, ((_a = process.env) === null || _a === void 0 ? void 0 : _a.JEST_WORKER_ID) ? 1 : seconds * 1000); });
const retry = (operation, delay = 2, retries = 3, onError) => {
return new Promise((resolve, reject) => {
return operation()
.then(resolve)
.catch((reason) => {
if (onError) {
onError(reason, retries);
}
if (retries > 0) {
return waitFor(delay)
.then(exports.retry.bind(null, operation, delay, retries - 1, onError))
.then(resolve)
.catch(reject);
}
return reject(reason);
});
});
};
exports.retry = retry;
//# sourceMappingURL=retry.helper.js.map