2 回答
TA贡献1827条经验 获得超9个赞
这是我使用 async/await 解决此问题的方法
const questionAction = async (question) => {
let respName = "";
let respObj = question;
if (question.type === "some_type") {
// some not important code
// respName = "some_name"
} else if (question.type === "some_typeN") {
// some not important code
// respName = "some_nameN"
} else if (question.type === "some_type4") {
respName = "some_name4"
respObj = await getBlockStats(handle, block);
} else {
// some not important code
// respName = "some_nameX"
}
setTimeout(() => {
io.emit(respName, respObj);
}, offset);
offset += offsetIncrease;
};
(async () => {
for (const question of questionList) {
await questionAction(question);
}
})()
添加回答
举报