2 ms·
The JS version can quickly be improved to use less memory (~10%). async function main() { const numTasks = parseInt(process.argv[2], 10); c
by win32_func 2y ago
The JS version can quickly be improved to use less memory (~10%).
async function main() {
const numTasks = parseInt(process.argv[2], 10);
const taskDuration = 10000; // 10 seconds
const tasks = Array.from({ length: numTasks }, () =>
new Promise(resolve => setTimeout(resolve, taskDuration))
);
await Promise.all(tasks); // Wait for all tasks to resolve
console.log("All tasks completed.");
}
main().catch(err => {
console.error("Error occurred:", err);
});