Skip to content

Instantly share code, notes, and snippets.

Created December 12, 2021 08:23
What would you like to do?
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