【发布时间】:2018-09-23 14:26:13
【问题描述】:
我在异步函数中使用 await 按特定顺序执行函数,如果您在这里看到 - 我希望 startAnim 等到 hideMoveUI 完成执行后自行执行。
虽然我的控制台日志返回:
startAnim
hideMoveUI
我的代码:
async function printAll() {
await hideMoveUI();
await startAnim();
}
printAll();
hideMoveUI = () => {
setTimeout(() => {
console.log('hideMoveUI');
}, 3000);
}
startAnim =() => {
setTimeout(() => {
console.log('startAnim');
}, 500);
}
setTimeout 是 async 函数吗?
如何让第二个函数等待第一个函数完成?任何帮助或建议表示赞赏。提前谢谢你。
【问题讨论】:
-
printAll() .then(() => hideMoveUI()) .then(() => startAnim =())
-
@Rajesh:不,不应该。
-
这是 ES2017,不是 ES7。
标签: javascript asynchronous async-await ecmascript-2017