Proof of Work · Challenge
Fifty uploads, but only three at a time.
about 35 min · 6 required tests · in the browser
What is recorded: when you save, your Result page shows your code, which tests passed, how many times you ran the tests, how many versions you tried, the time from first run to save, and the largest jump in code between runs. Anyone with the link can see it. The suggested time is not enforced.
Uploading fifty images at once floods the network. Uploading them one by one wastes time. A pool runs a few at a time and starts the next as soon as one finishes.
Implement promisePool(tasks, limit).
tasks is an array of functions. Each function takes no arguments and returns a promise (or a plain value). Calling the function starts the work. limit is the most tasks allowed to run at the same time.
promisePool returns a promise for an array of results, in the same order as tasks, whatever order they finished in.
With a limit of 2 and tasks that take 300, 100, 100, and 100 milliseconds:
const results = await promisePool([
() => upload("a"), // 300ms
() => upload("b"), // 100ms
() => upload("c"), // 100ms
() => upload("d"), // 100ms
], 2)
// t=0: a and b start
// t=100: b finishes, c starts
// t=200: c finishes, d starts
// t=300: a and d finish. results are in the order a, b, c, dThe grader moves time on a virtual clock. setTimeout and clearTimeout work. Time does not pass on its own, and setInterval is not available.
Requirements:
limit tasks at once.tasks.Write a top-level function named promisePool. Do not use export or module.exports.
Press Esc, then Tab, to leave the editor.
⌘ / Ctrl + Enter runs the tests
Hiring developers? See how teams use this.
Graded on
0/6
Other builds