doc: add other promise to pizza example

This commit is contained in:
Leon Xu committed 2021-10-17 16:54:52 -07:00
1 parent 62a3f7eb14
commit e55e3e546c
1 file changed
+17 -1
+17 -1
View File
@@ -195,4 +195,20 @@ function eat(value) {
let orderPizza = new Promise (orderExecutor);
orderPizza.then(eat).then(function (value) { console.log(value); });
```
```
你还可以返回其他promise,这些promise将暂停下一个then回调的执行,知道它被解决
```javascript
function eatExecutor(resolve, reject) {
console.log('eating our pizza...');
setTimeout(resolve, 3000)
}
function eat() {
return new Promise (eatExecutor);
}
let orderPizza = new Promise(orderExecutor);
orderPizza.then(eat).then(function () { console.log('Paying the bill!'); });
```