Skip to content

ExamplesAbort & Deduplication

Abort & Deduplication

Cancel in-flight requests with AbortController and deduplicate rapid calls.

both modes

Manual 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
idle
// run the request to see the response
Abort docs

Request Deduplication

Click the button rapidly — each click aborts the previous in-flight request. Only the last request completes.

ts
const abortRef = useRef<AbortController | null>(null)

function handleClick() {
  // Abort the previous in-flight request
  abortRef.current?.abort()

  const controller = new AbortController()
  abortRef.current = controller

  caller.users.with({ signal: controller.signal }).getAll()
}
caller.users.with({ signal }).getAll()SANDBOX

clicks 0aborted 0

idle
// run the request to see the response

deduplicate — HttpClient-Level Dedup

Source-level config that auto-aborts duplicate requests by path+method. Used in direct mode or persistent HttpClient scenarios.

ts
import { defineApi } from "@noverax/courier/define"

// deduplicate: true enables automatic deduplication
// at the HttpClient level — if the same path+method is called
// again while a request is in-flight, the old one is aborted
// with a 499 status code.

const api = defineApi({
  baseURL: "http://localhost:4000",
  groups,
  deduplicate: true,
})

When deduplicate: true is set, the HttpClient tracks in-flight requests by path and method. If a duplicate is fired, the previous one is aborted with status 499.