Last active
July 23, 2018 18:59
-
-
Save n370/3f5877a7226dfad7730b4fb25e8e4eb0 to your computer and use it in GitHub Desktop.
A naive example on how to schedule the execution in series of a list of async tasks.
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 characters
const a = []; | |
a.push(() => setTimeout(() => { console.log('a'); a.shift(); a.length && a[0]();}, 1000)) | |
a.push(() => setTimeout(() => { console.log('b'); a.shift(); a.length && a[0]();}, 1000)) | |
a.push(() => setTimeout(() => { console.log('c'); a.shift(); a.length && a[0]();}, 1000)) | |
a.push(() => setTimeout(() => { console.log('d'); a.shift(); a.length && a[0]();}, 1000)) | |
a.push(() => setTimeout(() => { console.log('e'); a.shift(); a.length && a[0]();}, 1000)) | |
a[0](); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment