BACK
Use casesPolling — refreshing data periodically
Use cases · 08

Polling — refreshing data periodically

Pattern

Polling is for when the server can't push: dashboards, task queues, upload statuses. We poll an endpoint periodically and swap the UI for the fresh response.

The operators and their roles

  • timer(0, period) — a tick generator: the first right away, then every period ms.
  • switchMap — if the previous request is still in flight, it's cancelled, so the UI always shows the latest response.
  • take(N) — cap the number of ticks (while the component is alive, for example).

What we achieve

One self-contained stream that manages the polling rate itself and never piles up response races.

script.ts // TypeScript
CONSOLE · Console output
Hit Run to see the result...