Created
August 11, 2015 08:39
-
-
Save anonymous/af0e21529ea84c9f4d89 to your computer and use it in GitHub Desktop.
Promise race excute // source https://jsbin.com/baxefi
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 race excute</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> | |
| // `delay`毫秒后执行resolve | |
| function timerPromisefy(delay) { | |
| return new Promise(function (resolve) { | |
| setTimeout(function () { | |
| resolve(delay); | |
| }, delay); | |
| }); | |
| } | |
| // 任何一个promise变为resolve或reject 的话程序就停止运行 | |
| Promise.race([ | |
| timerPromisefy(1), | |
| timerPromisefy(32), | |
| timerPromisefy(64), | |
| timerPromisefy(128) | |
| ]).then(function (value) { | |
| console.log(value); // => 1 | |
| }); | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">// `delay`毫秒后执行resolve | |
| function timerPromisefy(delay) { | |
| return new Promise(function (resolve) { | |
| setTimeout(function () { | |
| resolve(delay); | |
| }, delay); | |
| }); | |
| } | |
| // 任何一个promise变为resolve或reject 的话程序就停止运行 | |
| Promise.race([ | |
| timerPromisefy(1), | |
| timerPromisefy(32), | |
| timerPromisefy(64), | |
| timerPromisefy(128) | |
| ]).then(function (value) { | |
| console.log(value); // => 1 | |
| });</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); | |
| }); | |
| } | |
| // 任何一个promise变为resolve或reject 的话程序就停止运行 | |
| Promise.race([ | |
| timerPromisefy(1), | |
| timerPromisefy(32), | |
| timerPromisefy(64), | |
| timerPromisefy(128) | |
| ]).then(function (value) { | |
| console.log(value); // => 1 | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment