Created
April 25, 2025 19:08
-
-
Save rafaelcamargo/1dadfc3814db96e60326741f87317923 to your computer and use it in GitHub Desktop.
Async Task Runner
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 processTasks(tasks){ | |
if(!tasks?.length) return console.log('Finished'); | |
const [exec, ...rest] = tasks; | |
setTimeout(() => { | |
exec(); | |
processTasks(rest); | |
}); | |
} | |
const smallBatch = [ | |
() => console.log('Small A'), | |
() => console.log('Small B'), | |
() => console.log('Small C') | |
]; | |
const regularBatch = new Array(200) | |
.fill({}) | |
.map((item, index) => { | |
return function(){ console.log(`Regular ${index}`) }; | |
}); | |
const bigBatch = new Array(1000) | |
.fill({}) | |
.map((item, index) => { | |
return function(){ console.log(`Big ${index}`) }; | |
}); | |
processTasks(bigBatch); | |
processTasks(smallBatch); | |
processTasks(regularBatch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment