如何在async/await语法中使用Promise.prototype.finally()?

Ame*_*icA 12 javascript asynchronous async-await ecmascript-2017

实际上我的主要问题是Promise.prototype.catch()async/await ES8语法中使用,毫无疑问在语法的Promise.prototype.then()本质上存在async/await.

我搜索有关使用Promise.prototype.catch()async/await,发现了这个:

async () => {
  try {
    const result1 = await firstAsynchronousFunction();
    const result2 = await secondAsynchronousFunction(result1);
    console.log(result2);
  } catch(err) {
    throw new Error(`Something failed`);
  }
}
Run Code Online (Sandbox Code Playgroud)

绝对我知道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`);
})
Run Code Online (Sandbox Code Playgroud)

那么,我的问题是如何finallyasync/await语法中使用

jcu*_*bic 20

这应该工作:

async () => {
  try {
    const result1 = await firstAsynchronousFunction();
    const result2 = await secondAsynchronousFunction(result1);
    console.log(result2);
  } catch(err) {
    throw new Error(`Something failed`);
  } finally {
    console.log(`All Tasks is Done`);
  }
}
Run Code Online (Sandbox Code Playgroud)