Files
NapCatQQ/.pnpm-store/v3/files/fb/f65d592983b786f4df55fe54be8bfbe64b1642cb9bd0f5e44e12b14248df00b28501920ff911c99f4777ef59da4163b640c48a0125eb8ca8c01cd21f8c52c1
TanTan e311ca3275
Build NapCat Artifacts / Windows Loader Test (push) Canceled after 0s
Build NapCat Artifacts / Type Check & Test (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Framework (push) Canceled after 0s
Build NapCat Artifacts / Build NapCat.Shell (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

46 lines
1.5 KiB
Plaintext

import { useRef } from 'react';
var useRetryPlugin = function (fetchInstance, _a) {
var retryInterval = _a.retryInterval, retryCount = _a.retryCount;
var timerRef = useRef(undefined);
var countRef = useRef(0);
var triggerByRetry = useRef(false);
if (!retryCount) {
return {};
}
return {
onBefore: function () {
if (!triggerByRetry.current) {
countRef.current = 0;
}
triggerByRetry.current = false;
if (timerRef.current) {
clearTimeout(timerRef.current);
}
},
onSuccess: function () {
countRef.current = 0;
},
onError: function () {
countRef.current += 1;
if (retryCount === -1 || countRef.current <= retryCount) {
// Exponential backoff
var timeout = retryInterval !== null && retryInterval !== void 0 ? retryInterval : Math.min(1000 * Math.pow(2, countRef.current), 30000);
timerRef.current = setTimeout(function () {
triggerByRetry.current = true;
fetchInstance.refresh();
}, timeout);
}
else {
countRef.current = 0;
}
},
onCancel: function () {
countRef.current = 0;
if (timerRef.current) {
clearTimeout(timerRef.current);
}
},
};
};
export default useRetryPlugin;