Skip to content

Commit

Permalink
docs(promise): edit promise
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanyf committed Mar 1, 2018
1 parent 50bd8d0 commit 5338964
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions docs/promise.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,10 @@ const p = Promise.race([
setTimeout(() => reject(new Error('request timeout')), 5000)
})
]);
p.then(response => console.log(response));
p.catch(error => console.log(error));

p
.then(console.log)
.catch(console.error);
```

上面代码中,如果 5 秒之内`fetch`方法无法返回结果,变量`p`的状态就会变为`rejected`,从而触发`catch`方法指定的回调函数。
Expand Down

0 comments on commit 5338964

Please sign in to comment.