BACK
Lessons52. Project: sequential requests
Lessons · 52

52. Project: sequential requests

Project 4 — sequential loading

A real case: load the user's profile, then their orders by that user, then the total by those orders. These steps depend on each other, and order matters more than speed.

A quirk of the test

Notice: the second step, orders, is faster than the first, user (10ms vs 50ms). Had you used mergeMap, orders would arrive first. concatMap guarantees strict order.

Your task

  1. In loadSequentially$, inside pipe, add concatMap(step => loadStep(step)).
  2. Result order: user → orders → total.

Deterministic check

This task's check runs in TestScheduler virtual time. If your solution is right, the console shows only Test Passed!. Don't add extra console.logs, or the check will fail.

Solution spoiler · click to reveal
const { from, concatMap } = Rx;

function loadSequentially$(steps, loadStep) {
  return from(steps).pipe(
    concatMap(step => loadStep(step))
  );
}
script.ts // TypeScript
CONSOLE · Console output
Hit Run to see the result...