consume the result from await 和 return the result from await 有什么区别?

What is the difference between consume the result from await and return the result from await?

我对以下两个代码片段感到有点困惑:

async function f() {

  let promise = new Promise((resolve, reject) => {
    setTimeout(() => resolve("done!"), 1000)
  });

  let result = await promise; // wait until the promise resolves (*)

  return result; 
}
console.log(f()); //prints Promise { <pending> } at once then wait for 1 second before terminating

async function f() {

  let promise = new Promise((resolve, reject) => {
    setTimeout(() => resolve("done!"), 1000)
  });

  let result = await promise; // wait until the promise resolves (*)

  console.log(result); 
}

f(); //waits for 1 second and prints done! before terminating

我原以为上面的两个代码片段会产生相同的结果,例如打印完成! 1 秒后到控制台。是什么让第一个代码片段 return

What made the first code snippet return

两个代码片段 return 在同一点。 await 关键字,当它在 RHS 上获得承诺时,使它所属的函数进入休眠状态,直到该承诺得到解决。

与此同时,调用函数得到 f 的承诺 return 并继续 运行。

这就是使用 async 函数的意义所在:它们 在处理异步事物时不会阻塞