Email SDK
PluginsBuilt-in plugins

Timeout plugin

Bound one logical send, including retries and fallback, while preserving caller cancellation.

timeoutPlugin adds an AbortSignal.timeout to every send. When a caller already supplies a signal, the plugin combines both and aborts on whichever happens first.

src/email.ts
import { timeoutPlugin } from "@opencoredev/email-sdk/plugins/timeout";

const email = createEmailClient({
  adapters: [primary, backup],
  plugins: [timeoutPlugin({ timeoutMs: 10_000 })],
  retry: { maxAttempts: 2 },
  fallback: { adapters: ["backup"] },
});

The timeout covers the whole logical operation after beforeSend begins. It does not reset for each retry or fallback adapter. A timeout surfaces as EmailAbortError and stops routing.

Choose the bound from the user operation

Use a short timeout for request-response flows and a larger timeout in durable workers. The plugin is not a queue deadline and does not cancel a provider request after the provider has already accepted it.

timeoutMs must be a positive finite number. Use a custom id when registering multiple instances for separate composed clients.

Aborted error

Handle caller cancellation and timeout failures.

Production pipeline

Use durable worker deadlines and persisted recovery.

On this page