BACK
PracticeReal-life: exhaustMap() login double click
PRACTICE · 72 · 練

Real-life: exhaustMap() login double click

Two login clicks arrive at once. While the first request is active, the second should be ignored.

  1. Solve the task in the editor — no long theory.
  2. Run the check and compare your output with the expected result.
  3. Stuck? Open the solution and carry the approach into your own code.
Solution spoiler · click to reveal
const { of, timer, exhaustMap, map } = Rx;

const login = id => timer(0).pipe(map(() => 'login-' + id));

const result$ = of(1, 2).pipe(
  exhaustMap(id => login(id))
);

result$.subscribe(value => console.log(value));
script.ts // TypeScript
CONSOLE · Console output
Hit Run to see the result...