mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-25 19:22:21 +00:00
docs(async): async 语法
This commit is contained in:
parent
b39d0e606e
commit
36edba382d
@ -877,6 +877,21 @@ f()
|
|||||||
// hello world
|
// hello world
|
||||||
```
|
```
|
||||||
|
|
||||||
|
另一种方法是`await`后面的Promise对象再跟一个`catch`方面,处理前面可能出现的错误。
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
async function f() {
|
||||||
|
await Promise.reject('出错了')
|
||||||
|
.catch(e => console.log(e));
|
||||||
|
return await Promise.resolve('hello world');
|
||||||
|
}
|
||||||
|
|
||||||
|
f()
|
||||||
|
.then(v => console.log(v))
|
||||||
|
// 出错了
|
||||||
|
// hello world
|
||||||
|
```
|
||||||
|
|
||||||
(4)如果`await`后面的异步操作出错,那么等同于`async`函数返回的Promise对象被`reject`。
|
(4)如果`await`后面的异步操作出错,那么等同于`async`函数返回的Promise对象被`reject`。
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
Loading…
x
Reference in New Issue
Block a user