Created
September 7, 2017 15:13
-
-
Save LoLei/270e7f7a77f74df74bdd7f162ccd295d to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/zakoqan
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"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> | |
| "use strict"; | |
| var loop = function loop(i, array, increment) { | |
| var promises = []; | |
| for (var j = 0; j < increment; j++) { | |
| console.log(array[i + j]); | |
| promises.push(save(array[i + j])); | |
| } | |
| Promise.all(promises).then(function () { | |
| console.log("Done with " + increment + " promises."); | |
| }); | |
| }; | |
| console.log("start"); | |
| var array = []; | |
| for (var j = 0; j < 1000; j++) { | |
| array.push(j); | |
| } | |
| var amount = array.length; | |
| var increment = 10; | |
| for (var it = 0; it < amount; it += increment) { | |
| loop(it, array, increment); | |
| } | |
| console.log("end"); | |
| function save(x) { | |
| setTimeout(function () { | |
| console.log("Done saving: " + x); | |
| return Promise.resolve(1); | |
| }, 250); | |
| } | |
| </script> | |
| <script id="jsbin-source-javascript" type="text/javascript">var loop = function(i, array, increment) { | |
| var promises = []; | |
| for (var j = 0; j < increment; j++) { | |
| console.log(array[i + j]); | |
| promises.push(save(array[i + j])); | |
| } | |
| Promise.all(promises).then(function(){ | |
| console.log("Done with " + increment + " promises."); | |
| }); | |
| } | |
| console.log("start"); | |
| var array = []; | |
| for (var j = 0; j < 1000; j++) { | |
| array.push(j); | |
| } | |
| var amount = array.length; | |
| var increment = 10; | |
| for (var it = 0; it < amount; it+=increment) { | |
| loop(it, array, increment); | |
| } | |
| console.log("end"); | |
| function save(x) { | |
| setTimeout(function(){ | |
| console.log("Done saving: " + x); | |
| return Promise.resolve(1); | |
| }, 250); | |
| }</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
| "use strict"; | |
| var loop = function loop(i, array, increment) { | |
| var promises = []; | |
| for (var j = 0; j < increment; j++) { | |
| console.log(array[i + j]); | |
| promises.push(save(array[i + j])); | |
| } | |
| Promise.all(promises).then(function () { | |
| console.log("Done with " + increment + " promises."); | |
| }); | |
| }; | |
| console.log("start"); | |
| var array = []; | |
| for (var j = 0; j < 1000; j++) { | |
| array.push(j); | |
| } | |
| var amount = array.length; | |
| var increment = 10; | |
| for (var it = 0; it < amount; it += increment) { | |
| loop(it, array, increment); | |
| } | |
| console.log("end"); | |
| function save(x) { | |
| setTimeout(function () { | |
| console.log("Done saving: " + x); | |
| return Promise.resolve(1); | |
| }, 250); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment