码迷,mamicode.com
首页 > 其他好文 > 详细

async & await

时间:2017-09-25 16:05:13      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:com   try   sed   represent   row   throws   web   contain   tin   

await

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

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

  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.

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

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

async

  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.

参考:

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

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

async & await

标签:com   try   sed   represent   row   throws   web   contain   tin   

原文地址:http://www.cnblogs.com/tekkaman/p/7591924.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!