async await

2019-02-13  本文已影响0人  怎么昵称

await 后面跟一个promise对象
async是一个异步函数的标志 async function
let n= await xx() 错误
async function text(){
let n= await xx()
}

await 更像一个同步函数 特征就像是从上向下顺序执行语句

promise 明明显是异步函数 与之不同 与之相比 更加复杂 逻辑性更强

如果同时有多个函数 需要执行 await xx() 或者 await promise.all(f1(), f2())
或者直接 promise.all(f1(), f2()) 全都TRUE为TRUE 全部FALSE 为FALSE
promise.race(f1(), f2()) 一个为TRUE为TRUE 一个为FALSE为FALSE

上一篇 下一篇

猜你喜欢

热点阅读