← Back to demos

Async Search with Race Conditions

Type quickly to trigger race conditions. The API has random latency (200-1500ms).

State Machine Approach
idleRequest #0
Guards ensure only the current request's response is displayed.

Start typing to search...

Why this works:

  • • Each request gets a unique ID stored in context
  • • Guard checks: event.requestId === ctx.currentRequestId
  • • Stale responses are automatically rejected

The "Aha!" Moment:

Without state machines, you'd need to manually track request IDs, compare them in every response handler, and remember to do this consistently. With a state machine, the guard handles it automatically - stale responses simply don't trigger transitions.