Last active
July 31, 2017 23:06
-
-
Save jesuscast/d7b9d0a29dd921e03d932c117eeba8ce to your computer and use it in GitHub Desktop.
Revisions
-
jesuscast revised this gist
Jul 31, 2017 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains 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 @@ -16,7 +16,6 @@ function promiseReducer(arrayOfPromiseHolders, resolve, reject) { * resolves them in series * * Usage: * resolveInSeries([ * () => { * return new Promise((resolve) => { console.log("I will print first!"); resolve(); }) -
jesuscast created this gist
Jul 31, 2017 .There are no files selected for viewing
This file contains 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,37 @@ function promiseReducer(arrayOfPromiseHolders, resolve, reject) { if (arrayOfPromiseHolders.length > 0) { const promiseHolder = arrayOfPromiseHolders.shift(); promiseHolder().then(() => { promiseReducer(arrayOfPromiseHolders, resolve, reject); }).catch((err) => { reject(err); }); } else { resolve(); } } /** * Resolve in series takes an array of functions that return a promise, and then * resolves them in series * * Usage: * * resolveInSeries([ * () => { * return new Promise((resolve) => { console.log("I will print first!"); resolve(); }) * }, * () => { * return new Promise((resolve) => { console.log("I will print second!"); resolve(); }) * } * ]).then(() => { * console.log("I will print at the end"); * }); */ function resolveInSeries(arrayOfPromiseHolders) { return new Promise((resolve, reject) => { promiseReducer(arrayOfPromiseHolders, resolve, reject); }); } export resolveInSeries;