Last active
April 17, 2019 12:49
-
-
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
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
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