操作系统似乎刚刚删除了最后一个请求或其他什么? 通常我会期望超时,或者被阻止或者其他什么。
进入这种状态的请求似乎永远挂起。刷新浏览器似乎可以解决问题...
我正在开发一个 React 应用程序,使用 tanstack 来处理 graphql 请求。 有些客户遇到这样的问题...
我正在尝试使用超时解决我的 Tan Stack Graphql
useMutation
挂钩的此问题。
代码如下所示:
const DEFAULT_TIMEOUT = 10000;
export function withTimeout<T>(
promise: Promise<T>,
timeoutDuration: number = DEFAULT_TIMEOUT
): Promise<T> {
return new Promise((resolve, reject) => {
const timer = setTimeout(() => {
reject(new Error('Request timed out'));
}, timeoutDuration);
promise
.then(resolve)
.catch(reject)
.finally(() => clearTimeout(timer));
});
}
这个函数的使用方法如下:
const loginWithTimeout = withTimeout(
mutateAsync({
username,
password,
})
);
const { token, error } = await loginWithTimeout;
我还没有找到一种方法来向 Tan Stack 添加某种超时功能
queryClient
这是我迄今为止想到的最好的方法...