You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
parttimejob/node_modules/ali-oss/lib/common/utils/retry.js

31 lines
911 B

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.retry = void 0;
function retry(func, retryMax, config = {}) {
let retryNum = 0;
const { retryDelay = 500, errorHandler = () => true } = config;
const funcR = (...arg) => {
return new Promise((resolve, reject) => {
func(...arg)
.then(result => {
retryNum = 0;
resolve(result);
})
.catch(err => {
if (retryNum < retryMax && errorHandler(err)) {
retryNum++;
setTimeout(() => {
resolve(funcR(...arg));
}, retryDelay);
}
else {
retryNum = 0;
reject(err);
}
});
});
};
return funcR;
}
exports.retry = retry;