Identical reads share one request
Three identical reads start together. The browser counts the requests that reached the proxy.
ts
// 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 ownPromise. all([users. getAll(), users. getAll(), users. getAll()])SANDBOX
// run the request to see the responseCancel the previous call
The endpoint answers after 3 s. Call again before it does: the older call is cancelled with status 499, and the newer one is answered by the request already in flight.
ts
import { createProxyCaller } from "@noverax/courier"
import { apiRoutes } from "@/courier.routes"
const searchCaller = createProxyCaller(apiRoutes, {
cancelPrevious: ["misc.slow"],
})
// A newer call cancels the one still in flight: it rejects with status 499
await searchCaller.misc.slow()searchCaller. misc. slow()SANDBOX
// run the request to see the responseManual abort
Start a slow request (3s delay) and cancel it before it completes.
ts
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()caller. misc. with({ signal }). slow()SANDBOX
// run the request to see the response