This question already has answers here:
Combination of async function + await + setTimeout
(9个答案)
2年前关闭。
我的控制器有一个简单的示例,无法正常工作
输出:START,END,MIDDLE
预期:START,中,END
(9个答案)
2年前关闭。
我的控制器有一个简单的示例,无法正常工作
export let create = async (req: Request, res: Response) => {
console.log("START");
await setTimeout(() => {
console.log("MIDDLE");
}, 1000);
console.log("END");
return res.json({ data: null });
};
输出:START,END,MIDDLE
预期:START,中,END
最佳答案
尝试:await new Promise(resolve => setTimeout(resolve, 1000))
关于javascript - NodeJ- Controller 内的Async/Await ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47993864/