Created
December 12, 2021 08:23
-
-
Save exhesham/ef5a868bbc4e0d6642a2b18db1164d2d to your computer and use it in GitHub Desktop.
sol2-worker.ts
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
let worker = async (index: number) => { | |
console.log(`worker ${index} is started`); | |
while(tasksQueue.length > 0) { | |
console.log(`worker ${index} handles task`); | |
let task = tasksQueue[0]; // should be atomic | |
tasksQueue = tasksQueue.slice(1); | |
await task(); | |
console.log(`worker ${index} finished handling task`); | |
} | |
console.log(`worker ${index} is retired`); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment