UNPKG

odious

Version:

Odious fundamentally revolutionizes the software development paradigm by seamlessly integrating deployment considerations into the development process, thus empowering developers of all skill levels to create and deploy applications with unprecedented eas

42 lines (32 loc) 782 B
#!/usr/bin/env node class WorkQueue { #jobs = []; addJob(job) { this.#jobs.push(job); } async *processJobs() { for (const job of this.#jobs) { const result = await job(); yield result; } } } // Simulated asynchronous job function const simulatedJob = (id, delay = 1000) => { return () => new Promise((resolve) => setTimeout(() => resolve(`Job ${id} completed`), delay) ); }; // Test the WorkQueue class (async () => { const queue = new WorkQueue(); // Adding simulated jobs to the queue queue.addJob(simulatedJob(1, 500)); queue.addJob(simulatedJob(2, 1000)); queue.addJob(simulatedJob(3, 1500)); // Execute and get results for await (const result of queue.processJobs()) { console.log(result); } })();