AniUI Academy
easy+150 XPPractice

Run async tasks one after another

Promise.all starts everything at once, which is usually what you want and occasionally a disaster — think four PUT requests to the same record, or an endpoint that returns 429 the moment you exceed one call at a time.

Implement runSequentially(tasks), where tasks is an array of zero-argument functions that each return a promise. Call the first task, wait for it to settle, then call the next, and so on. Resolve with an array of the results in the same order as tasks. An empty array resolves with an empty array. If a task rejects, reject immediately with that same reason and do not call any of the remaining tasks.

What it has to do

  • Never have more than one task running at a time.
  • Resolve with results in the order the tasks were given.
  • Resolve with [] when tasks is empty.
  • Reject with the first rejection reason and skip the remaining tasks.

Your workspace

Try it yourself
Loading playground...

Ready to check it?

4 tests run against your code, right here in your browser. Sign in to claim the XP when you pass.

AI Crack & Solution Assist

Stuck? Get instant AI hints or break down the optimal solution.

Stuck? The javascript course covers everything this challenge needs.