A ferry board has two routes; only the most recent selection should win. The preview is intentionally powered by an explicit in-page mock fetch, so it works offline and never claims to show live data.
The previous district lookup canceled a slow old request. Now a ferry board must do the same for two route buttons. The supplied mockFetch(url, { signal }) records a local request, waits for a predictable timer, and rejects with AbortError if canceled. It never contacts a ferry service.
For an unrelated temperature display the pattern is:
let currentController;
async function checkWeather(city) {
currentController?.abort();
currentController = new AbortController();
try {
const response = await mockFetch(`/api/weather?city=${encodeURIComponent(city)}`, {
signal: currentController.signal
});
const data = await response.json();
label.textContent = data.summary;
} catch (error) {
if (error.name !== "AbortError") label.textContent = "Lookup failed.";
}
}
In the ferry board, click Slow pier and immediately Fast pier. The board should end on Fast even when the slow timer has elapsed. AbortError is not a service outage; don't replace the newer loading or ready message with an error from the canceled request. Run the preview, then Submit for checks that exercise both cancellation and the final DOM state.
mockFetch for their route and immediately announce Loading route….AbortController and pass each request its controller’s signal.Route ready. after its response arrives.AbortError so it never replaces the newest route’s ready status with an error.