Implement a scheduler that starts at most limit promise-returning tasks at a time and resolves results in input order.
Requirements
Reject a non-positive limit
Preserve result order
Do not start more than limit tasks simultaneously
Show a hint
Write down the input contract and the failure cases before coding.
tests
RUNTIME OUTPUT
Ready to run the file open above against 0 tests.
Runs the open file in a restricted browser worker
LEARN FROM THE SOLUTION
Why the solution works.
Workers share one next index; JavaScript runs each synchronous increment atomically before an await yields control. There are never more workers than the limit, and storing each result by its original index preserves caller order even when tasks finish out of order.
What this exercise teaches
Promises
Concurrency
Queue invariants
A PRACTICAL PLAN
Work through Limit concurrent async tasks with intent.
Translate the contract.Turn the requirements into a short checklist before editing your-solution.js.
Use the example as evidence.Predict the result for the supplied input, then add one boundary case such as an empty value, a limit, or unexpected input.
Review the implementation.Compare your choices against solution.js only after a real attempt.
EXERCISE FAQ
Before you move on.
What does “Limit concurrent async tasks” teach?
This advanced JavaScript exercise focuses on Promises, Concurrency, Queue invariants. Its requirements define the exact behavior to implement before you write code.
How should I validate this JavaScript solution?
Open your-solution.js and select Run code. The browser executes that file in an isolated worker against the visible test cases.
When should I open the reference solution?
Attempt Limit concurrent async tasks first. Then open the read-only solution file to compare the contract, edge-case handling, and implementation choices—not simply to copy the final code.