BACK
Use casesSubmit queue — submissions strictly in order
Use cases · 16

Submit queue — submissions strictly in order

Pattern

Not to be confused with double-click protection! Here every submit matters — these are distinct requests, wizard steps, separate admin commands. They must all reach the server, and in the same order the user sent them.

The problem it solves

Use exhaustMap (double-submit protection) and we lose important commands. Use switchMap and we cancel the previous submission, which is catastrophic for mutating requests. Use mergeMap and we send them in parallel, so the backend receives them in random order.

Operators and why they matter

  • concatMap — subscribes to the next request only after the previous one completes. That's the queue.
  • timer + map — simulate a network request for the demo.

Gotchas

  • exhaustMap is right for a "Pay" button (dedup protection), but it would drop important submit events from the queue.
  • switchMap cancels the previous submission — you can't use it for mutating requests that may already be partly saved.
  • If an error reaches inside concatMap, the whole queue dies. In production, add a catchError at each item's level.

What you get

Every submit command reaches the server one after another, in exact order of arrival. Nothing is lost or reordered.

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