Files
NapCatQQ/.pnpm-store/v3/files/66/d277e488999b5f8393f0d7ed14737e78a847a24aac5d38e483022e3d91fcb859928ecf393c26db1a9c6fed581c98beba720af7dffaf90a6d46580e6ef59968
T
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

51 lines
1.5 KiB
Plaintext

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = require("react");
var useRetryPlugin = function useRetryPlugin(fetchInstance, _a) {
var retryInterval = _a.retryInterval,
retryCount = _a.retryCount;
var timerRef = (0, _react.useRef)(undefined);
var countRef = (0, _react.useRef)(0);
var triggerByRetry = (0, _react.useRef)(false);
if (!retryCount) {
return {};
}
return {
onBefore: function onBefore() {
if (!triggerByRetry.current) {
countRef.current = 0;
}
triggerByRetry.current = false;
if (timerRef.current) {
clearTimeout(timerRef.current);
}
},
onSuccess: function onSuccess() {
countRef.current = 0;
},
onError: function onError() {
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 onCancel() {
countRef.current = 0;
if (timerRef.current) {
clearTimeout(timerRef.current);
}
}
};
};
var _default = exports["default"] = useRetryPlugin;