From 072ccf42c91693215ffe99efd65ecdb4408534e6 Mon Sep 17 00:00:00 2001 From: Leon Xu <6479451-leonxu260@users.noreply.gitlab.com> Date: Sun, 17 Oct 2021 16:54:52 -0700 Subject: [PATCH] doc: add other promise to pizza example --- source/_posts/异步JavaScript.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/source/_posts/异步JavaScript.md b/source/_posts/异步JavaScript.md index c097826..579eabf 100644 --- a/source/_posts/异步JavaScript.md +++ b/source/_posts/异步JavaScript.md @@ -195,4 +195,20 @@ function eat(value) { let orderPizza = new Promise (orderExecutor); orderPizza.then(eat).then(function (value) { console.log(value); }); -``` \ No newline at end of file +``` + +你还可以返回其他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!'); }); +```