Last active
March 21, 2017 12:24
-
-
Save iamso/0983e547b7b007d821bd95f01fe15890 to your computer and use it in GitHub Desktop.
Revisions
-
iamso revised this gist
Mar 21, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ // the array to loop through const arr = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; // start with a resolved promise let p = Promise.resolve(); -
iamso revised this gist
Mar 21, 2017 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,8 +10,10 @@ for (let i of arr) { // create promise chain p = p.then(() => { // return the promise for chaining return functionWithPromise(i); }); } @@ -27,6 +29,7 @@ function functionWithPromise(text) { // simulate asyncronous activity setTimeout(() => { // end the function console.log(`end promise: ${text}`); -
iamso created this gist
Mar 21, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ // the array to loop through const arr = [0,1,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; // start with a resolved promise let p = Promise.resolve(); // loop through the array for (let i of arr) { // create promise chain p = p.then(() => { // return the promise for chaining return functionWithPromise(i); }); } // dummy function with promise function functionWithPromise(text) { // return a promise return new Promise((resolve, reject) => { // start the function console.log(`start promise: ${text}`); // simulate asyncronous activity setTimeout(() => { // end the function console.log(`end promise: ${text}`); // resolve the promise resolve(text); }, 1000); }); }