Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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