Skip to content

Instantly share code, notes, and snippets.

@hcl1687
Last active April 10, 2017 06:07
Show Gist options
  • Save hcl1687/61b9d6570d886bd7686251cfe97d19f6 to your computer and use it in GitHub Desktop.
Save hcl1687/61b9d6570d886bd7686251cfe97d19f6 to your computer and use it in GitHub Desktop.
runStep.js
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