用户单击登录后,我需要每3秒检查一次服务器状态。检查20次后,显示超时并清除计时器。
我的代码:
onCheckStatus = () => {
MAX_POLLING_COUNT = 20;
this.timer = setInterval(() => {
if (MAX_POLLING_COUNT > 0) {
MAX_POLLING_COUNT -= 1;
loginStatus(this.state.sessionId).then(
res => {
const { goto, sessionId, errorMessageCode, result, hint } = res;
........
if (goto === 'SUCCESS') {
this.setState({
messageInfo: {
type: 'success',
title: '',
description: result.description,
},
});
} else if (goto === 'ERROR') {
}
},
() => {
clearInterval(this.timer);
this.setState({ error: true, loading: false });
}
);
} else {
this.setState({ error: …Run Code Online (Sandbox Code Playgroud)