AniUI Academy
medium+250 XPPractice

Compose async steps into a pipeline

Upload a file, then resize it, then persist a record, then return the URL. Written with nested .then() calls it becomes a staircase; as a pipeline it reads as a list of named steps.

Implement pipeAsync(...fns). It returns a function that takes one input value and passes it through every step from left to right, awaiting each step's result before calling the next. Steps may be synchronous or return promises. It resolves with the final value. With no steps at all it resolves with the input unchanged. If a step throws or rejects, reject with that reason and do not call any later step.

What it has to do

  • Apply the steps left to right, one at a time.
  • Await each step before starting the next.
  • Support steps that return a plain value as well as a promise.
  • Resolve with the input unchanged when there are no steps.
  • Reject on the first failing step and skip the rest.

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.