简单的异步函数async/await例子
function resolveAfter2Seconds(x){ return new Promise(resolve => { setTimeout(() => { resolve(x) }, 2000) }); } async function f1() { var x = await resolveAfter2Seconds(10); console.log(x) } f1()
function resolveAfter2Seconds(x){ return new Promise(resolve => { setTimeout(() => { resolve(x) }, 2000) }); } async function f1() { var x = await resolveAfter2Seconds(10); console.log(x) } f1()