doc: add other promise to pizza example
This commit is contained in:
1 parent
62a3f7eb14
commit
e55e3e546c
1 file changed
+17
-1
@@ -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!'); });
|
||||
```
|
||||
Reference in new issue
Block a user