问题描述
在我的 react redux 应用中,使用 saga 和 superagent 客户端进行异步 https api 调用。
Api 保持挂起状态大约 4-5 秒,然后下面是时序分析我得到的节目花了几毫秒来响应。但在时钟上花了 5 秒。为什么会有这种滞后。即使没有其他并行请求,也会发生这种情况
如果我通过邮递员或 curl 访问相同的 api。以毫秒为单位更快地响应。
下面是api客户端代码:
constructor() {
methods.forEach(
method =>
(this[method] = (
path: string,{ params,data,timeout,authToken }: APIRequest = {}
) =>
new Promise((resolve,reject) => {
const request = superagent[method](formatUrl(path));
request.timeout(timeout || 60000);
request.set('Authorization',authToken || this.getToken());
if (params) {
request.query(params);
}
if (data) {
request.send(data);
}
request.then((body: Response) => {
resolve(body.body)
}).catch((err: ResponseError) => {
// HACK to redirect to session expired
if (err.status === 401) {
if (window.location.href.indexOf('/customer/') > -1) {
window.history.pushState('','','/customer/session-expired')
} else {
window.history.pushState('','/designer/session-expired')
}
}
reject(err)
});
}))
);
}
const result = yield SpacecraftBackendClient.post(
`/api/v1.0/xyz/${abc}/init3D`,{
data: {
abc,sessionId,xyz: convertConnectionType(controller)
}
},);
yield takeLatest(cartActionTypes.INIT_3D,init3D);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)