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
errorevent 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.