Skip to content

Instantly share code, notes, and snippets.

@exhesham
Created December 12, 2021 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save exhesham/ef5a868bbc4e0d6642a2b18db1164d2d to your computer and use it in GitHub Desktop.
Save exhesham/ef5a868bbc4e0d6642a2b18db1164d2d to your computer and use it in GitHub Desktop.
sol2-worker.ts
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