-
-
Save Phinome/7fa27f40b326e1d746b8 to your computer and use it in GitHub Desktop.
Promise all excute // source https://jsbin.com/qivujag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Promise all excute</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> | |
| // `delay`毫秒后执行resolve | |
| function timerPromisefy(delay) { | |
| return new Promise(function (resolve) { | |
| setTimeout(function () { | |
| resolve(delay); | |
| }, delay); | |
| }); | |
| } | |
| var startDate = Date.now(); | |
| // 所有promise变为resolve后程序退出 | |
| Promise.all([ | |
| timerPromisefy(1), | |
| timerPromisefy(32), | |
| timerPromisefy(64), | |
| timerPromisefy(128) | |
| ]).then(function (values) { | |
| console.log(Date.now() - startDate + 'ms'); | |
| // ~128ms | |
| console.log(values); // [1,32,64,128] | |
| }); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">// `delay`毫秒后执行resolve | |
| function timerPromisefy(delay) { | |
| return new Promise(function (resolve) { | |
| setTimeout(function () { | |
| resolve(delay); | |
| }, delay); | |
| }); | |
| } | |
| var startDate = Date.now(); | |
| // 所有promise变为resolve后程序退出 | |
| Promise.all([ | |
| timerPromisefy(1), | |
| timerPromisefy(32), | |
| timerPromisefy(64), | |
| timerPromisefy(128) | |
| ]).then(function (values) { | |
| console.log(Date.now() - startDate + 'ms'); | |
| // ~128ms | |
| console.log(values); // [1,32,64,128] | |
| });</script></body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // `delay`毫秒后执行resolve | |
| function timerPromisefy(delay) { | |
| return new Promise(function (resolve) { | |
| setTimeout(function () { | |
| resolve(delay); | |
| }, delay); | |
| }); | |
| } | |
| var startDate = Date.now(); | |
| // 所有promise变为resolve后程序退出 | |
| Promise.all([ | |
| timerPromisefy(1), | |
| timerPromisefy(32), | |
| timerPromisefy(64), | |
| timerPromisefy(128) | |
| ]).then(function (values) { | |
| console.log(Date.now() - startDate + 'ms'); | |
| // ~128ms | |
| console.log(values); // [1,32,64,128] | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment