BACK
Lessons19. delay: postpone values
Lessons · 19

19. delay: postpone values

delay — postpone delivery

delay(ms) doesn't change the values themselves or how many there are. It only postpones their delivery to the subscriber by the given number of milliseconds.

of('A', 'B').pipe(delay(20))
// 20ms of nothing → next('A') → next('B') → complete()

When it's used

  • Stubbing an HTTP request in tests and demos.
  • Delaying a "Loading" indicator so it doesn't flicker on fast responses.
  • Getting a feel for async — practice seeing the order of events.

Your task

  1. Inside pipe, add delay(20).
  2. Both values A and B come out together after 20 virtual milliseconds.

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 { of, delay } = Rx;

const result$ = of('A', 'B').pipe(
  delay(20)
);
script.ts // TypeScript
CONSOLE · Console output
Hit Run to see the result...