Last active
April 10, 2017 06:07
-
-
Save hcl1687/61b9d6570d886bd7686251cfe97d19f6 to your computer and use it in GitHub Desktop.
runStep.js
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
export function runSteps (arr) { | |
if (arr.length === 0) { | |
return | |
} | |
return arr.reduce(function(promise, item) { | |
return promise.then(createStep(item)) | |
}, Promise.resolve([])) | |
} | |
function createStep ({ step, timeout }) { | |
return new Promise(function (resolve, reject) { | |
setTimeout(function () { | |
try { | |
resolve(step()) | |
} catch (err) { | |
reject(err) | |
} | |
}, timeout || 0) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment