Skip to content

Instantly share code, notes, and snippets.

@brospars
Last active April 17, 2019 12:49
Show Gist options
  • Save brospars/dba3f11c195c24e58d4b6839fe207a53 to your computer and use it in GitHub Desktop.
Save brospars/dba3f11c195c24e58d4b6839fe207a53 to your computer and use it in GitHub Desktop.
A step by step script with delay between each action, demo : https://brospars.github.io/snippets/step-by-step
function nextStep(cb, ...args) {
setTimeout(() => {
cb(...args)
}, 1000)
}
function step1(foo){
// some logic and pass result to next step
var bar = foo * 2
nextStep(step2, foo, bar)
}
function step2(foo, bar){
// some logic and pass result to next step
var foobar = (foo + bar) * 2
nextStep(step3, foo, bar, foobar)
}
function step3(foo, bar, foobar){
// some logic and pass result to next step
console.log(foo + bar + foobar)
}
step1(2) // logs '18' after some time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment