The Real Fullstack

The Stale Search Results

The user typed “kafka”. The page shows results for “kaf”. Nobody typed “kaf” last.

Engenheiro8 minSimulador de linha do tempoDesafio de código
angularrxjstypescriptreacthttp

Este desafio ainda não foi traduzido para Português (Brasil). Você está lendo a versão em inglês.

Missão:Reproduce the race between overlapping requests, then pick a strategy that always shows results for the latest query, quickly, without hammering the API.Contexto · Objetivos de aprendizagem ▾

Larkspur's event search sends a request on every keystroke. The backend is usually fast, but some short queries are expensive and slow. Users report that results sometimes “jump back” to an older search after a moment.

Missão: Reproduce the race between overlapping requests, then pick a strategy that always shows results for the latest query, quickly, without hammering the API.

Objetivos de aprendizagem

  • Explain why responses can arrive out of order.
  • Compare mergeMap, concatMap, exhaustMap and switchMap.
  • Cancel stale requests and debounce input.
SimulaçãoSimulado

Execute a simulação para ver a saída.

Executar simulação
readonly results = toSignal(  this.query.valueChanges.pipe(    mergeMap((q) => this.api.search(q)),   // every response is rendered, in arrival order  ), { initialValue: [] });

Simplificação

Four keystrokes with fixed latencies. Real latencies vary, which makes the race intermittent and hard to reproduce. Modelo educacional — os números ilustram comportamento, não são benchmarks.

Conceitos

Útil antes deste

Desafios relacionados

Referências