Identical reads share one request
Three identical reads start together. The browser counts the requests that reached the proxy.
// Three components read the same list at the same moment
const [header, sidebar, page] = await Promise.all([
caller.users.getAll(),
caller.users.getAll(),
caller.users.getAll(),
])
// One request reached the proxy; each call got a copy of its own// run the request to see the responseRequests
as the browser recorded them and the site's server told of them
Cancel the previous call
The endpoint answers after 3 s. Call again before it does: the older call is cancelled with an AbortError, its code SUPERSEDED, and the newer one is answered by the request already in flight.
import { createProxyCaller } from "@noverax/courier/client"
import { routes } from "@noverax/courier/routes"
const caller = createProxyCaller(routes.api)
// A newer call made the same way cancels the one still in flight, which rejects with an
// AbortError whose code is "SUPERSEDED"
await caller.misc.with({ cancelPrevious: true }).slow()
// Or once for every call of the endpoint, where it is defined:
// slow: endpoint.get("slow").cancelPrevious()// run the request to see the responseRequests
as the browser recorded them and the site's server told of them
Manual abort
Start a slow request (3s delay) and cancel it before it completes.
const controller = new AbortController()
// Pass signal via .with() to cancel the request at any time
const promise = caller.misc.with({ signal: controller.signal }).slow()
// Cancel the request
controller.abort()// run the request to see the responseCancelled, the request gets no answer, so the site's server has none to tell its side in: it stops its own request to the API as the browser leaves. Chrome records the cancelled request below; Safari records none. Your browser's developer tools show it under Network as cancelled.
Requests
as the browser recorded them and the site's server told of them