AniUI Academy
hard+350 XPPractice

Pipe async steps in sequence

A request pipeline is rarely all synchronous: parse the input, fetch something, validate the response, map it to view state. Some steps return promises and some do not, and they must run in order because each depends on the last — which rules out Promise.all and rules out forEach.

Implement pipeAsync(...fns). It returns an async function that calls the leftmost function with all of the arguments it received, awaits the result, passes that value to the next function, and so on left to right, resolving with the last function's value. Steps run strictly in sequence: a step is not started until the previous one has settled. Steps may be synchronous or asynchronous and are treated identically. If any step throws or returns a rejected promise, the returned promise rejects with that error and no later step is called. With no functions at all, the returned function resolves with its first argument unchanged.

What it has to do

  • Thread the value left to right, awaiting each step before starting the next.
  • Treat synchronous and promise-returning steps identically.
  • Pass every argument to the leftmost step.
  • Reject with the first error, whether thrown synchronously or rejected, and skip the remaining steps.
  • With no functions, resolve with the first argument unchanged.

Your workspace

Try it yourself
Loading playground...

Ready to check it?

5 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.