Reactjs 如何在React-Redux传奇中为yield调用设置超时
在我的RESTAPI后端,我做了大量的处理,通常需要1.5分钟才能产生结果,在这段时间里,我的前端react应用程序出现了这个错误Reactjs 如何在React-Redux传奇中为yield调用设置超时,reactjs,react-redux,redux-saga,Reactjs,React Redux,Redux Saga,在我的RESTAPI后端,我做了大量的处理,通常需要1.5分钟才能产生结果,在这段时间里,我的前端react应用程序出现了这个错误 Error: timeout of 60000ms exceeded 因此,对等连接丢失 如何在redux saga中设置请求超时 import { eventChannel, END } from 'redux-saga' function countdown(secs) { return eventChannel(emitter => {
Error: timeout of 60000ms exceeded
因此,对等连接丢失
如何在redux saga中设置请求超时
import { eventChannel, END } from 'redux-saga'
function countdown(secs) {
return eventChannel(emitter => {
const iv = setInterval(() => {
secs -= 1
if (secs > 0) {
emitter(secs)
} else {
// this causes the channel to close
emitter(END)
}
}, 1000);
// The subscriber must return an unsubscribe function
return () => {
clearInterval(iv)
}
}
)
}
希望这能有所帮助。我习惯于做这样的事情。也许对你有用
export function* create(action) {
try {
const { payload } = action;
const response = yield call(api.addPost, payload);
if (response.status === 200) {
console.log('pass 200 check');
yield put(appActions.setResourceResponse(response.data));
console.log(response.data);
payload.push('/add-news');
}
} catch (error) {
console.log(error);
yield put(
a.setResponse({
message: error.response.data,
status: error.response.status,
}),
);
}
}
const {posts, timeout} = yield race({
posts: call(fetchApi, '/posts'),
timeout: delay(60 * 1000)
});
if (timeout) throw new Error('timeout of 60000ms exceeded')
发生这种情况的原因可能有很多,但您尚未给出应用程序设置的任何细节。您是否检查了Web服务器/代理的超时限制?react进行的前端ajax调用是否有超时限制?超时发生在django rest API的API调用期间