【发布时间】:2019-12-07 09:40:38
【问题描述】:
在下面的代码中,我想按此顺序获取 msg#1、msg#2、msg#3。我现在得到:味精#1,味精#3,味精#2。感谢帮助 !拒绝
function timeoutPromise(time) { return new Promise(function (resolve) { setTimeout(function () { resolve(Date.now()); }, time) }) }
function wait(howlong) { return timeoutPromise(howlong * 1000); }
async function doAsync() {
var start = Date.now(), time;
time = await wait(1); console.log('... ' + (time-start)/1000 );
time = await wait(1); console.log('... ' + (time-start)/1000 );
}
console.log('msg#1');
(async () => { await doAsync(); console.log('msg#2'); })();
console.log('msg#3');
【问题讨论】:
标签: asynchronous async-await iife