The screenshot API for developers -
Try ScreenshotOne
Skip to content

Timeout Plugin

Timeout Plugin automatically aborts requests that exceed a given timeout with an AbortError.

Usage

ts
import { TimeoutLinkPlugin } from '@orpc/client/plugins'

const link = new RPCLink({
  plugins: [
    new TimeoutLinkPlugin({
      timeout: 10_000, // 10 seconds
    }),
  ],
})

INFO

The link can be any supported oRPC link, such as RPCLink, OpenAPILink, or a custom one.

Dynamic Timeout

The timeout option also accepts a function, so you can resolve the timeout per request from the interceptor options, such as the procedure path or the client context:

ts
const link = new RPCLink({
  plugins: [
    new TimeoutLinkPlugin({
      timeout: ({ context, path }) => context.timeout ?? 10_000,
    }),
  ],
})

INFO

Return null or undefined to disable the timeout, which is useful for excluding long-lived requests. Any number always enables the timeout.

Learn More

For implementation details, see the source code.

Released under the MIT License.