Skip to content
You are reading the v2 docs, currently in beta.V1 docs
oRPC
Esc
↑↓navigate↵open⌘Jpreview
On this page

Signal Sync Plugin

Keep the request signal and streaming responses in sync, aborting the signal when the body is cancelled and ending the body when the signal aborts.

When a client stops reading a streaming response, adapters like Node.js abort the request signal, but in-process fetch calls and some runtimes behind the Fetch adapter only cancel the response body, so a procedure waiting on something keeps running. In the other direction, an aborted signal only ends the body once the procedure honors it.

Setup

Use SignalSyncHandlerPlugin to keep the request signal and streaming outputs (AsyncIteratorObject or ReadableStream) in sync:

  • When the output is cancelled before it finishes, the signal aborts with an AbortError.
  • When the signal aborts, the output ends with the abort reason, an error event for an AsyncIteratorObject, and is cancelled, even if the procedure ignores the signal.
import { SignalSyncHandlerPlugin } from '@orpc/server/plugins'

const handler = new RPCHandler(router, {
  plugins: [
    new SignalSyncHandlerPlugin(),
  ],
})

Learn More

For implementation details, see the source code.

Last updated on

Was this page helpful?