async
await
async function getStockPriceByName(name) {
const symbol = await getStockSymbol(name);
const stockPrice = await getStockPrice(symbol);
return stockPrice;
}
getStockPriceByName('goog').then(function (result) {
console.log(result);
});async function f() {
return 'hello world';
}
f().then(v => console.log(v))
// "hello world"await
案例:按顺序完成异步操作
遍历器异步
最后更新于