Blog

Latest input wins: the 500 ms debounce, precisely

Every keystroke invalidates the last result. How PostLens guarantees you never see a score for a draft you already changed — even when the network disagrees.

The core correctness property of a live analyzer is simple to state and easy to get wrong: the panel must never show a number for text you have already changed. Debouncing on a timer is not enough — a slow request for an old draft can land after a fast request for a new one.

A version counter is the boundary

PostLens dispatches analysis 500 ms after you stop typing. But the guarantee does not rest on the timer. Every update() increments a monotonic version, and a result is only rendered if its version is still the latest. Anything older is stale and shows an em dash, never a number.

type here ──▶ v5 (500 ms idle) ──▶ dispatch v5
  keep typing ──▶ v6            (v5 now stale)
  v5 response arrives ──▶ dropped, panel stays “—”
  v6 response arrives ──▶ rendered

AbortController cancels the older request too, but that is best-effort only. The version check is the guarantee; the abort is an optimisation. On the server, a newer request for the same session aborts the older one, which returns 409 SUPERSEDED.

500 ms is idle-to-dispatch, not end-to-end

The 500 ms is the pause before we send, not a promise about how long scoring takes. The panel always shows the real request latency and the provider mode, so you are never guessing whether you are looking at a live Jev result or the offline demo heuristic.