【发布时间】:2018-10-26 15:40:27
【问题描述】:
实际上我的主要问题是在async/await ES8 语法中使用Promise.prototype.catch(),毫无疑问Promise.prototype.then() 存在于async/await 语法的本质中。
我在async/await 中搜索了有关使用Promise.prototype.catch() 的信息,发现:
async () => {
try {
const result1 = await firstAsynchronousFunction();
const result2 = await secondAsynchronousFunction(result1);
console.log(result2);
} catch(err) {
throw new Error(`Something failed`);
}
}
而且我绝对知道Promise 链接,例如:
new Promise((resolve) => {
console.log(`Initial`);
resolve();
})
.then(() => {
console.log(`Task Number One`);
})
.catch(() => {
console.log(`Task in Error`);
})
.finally(() => {
console.log(`All Tasks is Done`);
})
所以,我的问题是如何在async/await 语法中使用finally?
【问题讨论】:
标签: javascript asynchronous async-await ecmascript-2017