async & await

awaitexpress

  The await operator is used to wait for a Promise. It can only be used inside an async function.promise

  Returns the resolved value of the promise, or the value itself if it's not a Promise.async

  The await expression causes async function execution to pause, to wait for the Promise's resolution, and to resume the async function execution when the value is resolved. It then returns the resolved value. If the value is not a Promise, it's converted to a resolved Promise.ide

  If the Promise is rejected, the await expression throws the rejected value.spa

async function f3() {
  try {
    var z = await Promise.reject(30);
  } catch(e) {
    console.log(e); // 30
  }
}
f3();

asynccode

  When an async function is called, it returns a Promise. When the async function returns a value, the Promise will be resolved with the returned value.  When the async function throws an exception or some value, the Promise will be rejected with the thrown value.blog

參考:ip

一、https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/awaitget

二、https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_functionit

相關文章
相關標籤/搜索