Skip to content

withSignal

withSignal<transport>(transport, signal): transport

Defined in: packages/synapse-core/src/utils/abort.ts:82

Wrap a viem transport so its requests reject with iso-web’s AbortError once the signal aborts.

Unlike passing fetchOptions.signal to viem’s http transport, this keeps the transport’s own request timeout and retries. For the default Filecoin transports, getTransport(chain, { signal }) does this for you. Requests in flight are not cancelled, only the wait for them; requests made after the signal aborted reject without being sent.

Limits:

  • Contract reads reject with viem’s ContractFunctionExecutionError, with the AbortError in its cause chain. Wrap the call in abortable to reject with the AbortError itself.
  • The transport’s retries for a request in flight keep sending after the abort; the caller only stops waiting for them.
  • viem’s waitForTransactionReceipt swallows polling errors, so on a withSignal client it runs until its timeout. Wrap receipt waits in abortable instead.
Type Parameter Description
transport extends Transport The transport to wrap.
Parameter Type Description
transport transport -
signal AbortSignal | undefined The signal to abort requests. The transport is returned as is when undefined.

transport

The wrapped transport.

import { createPublicClient, http } from 'viem'
import { calibration } from '@filoz/synapse-core/chains'
import { withSignal } from '@filoz/synapse-core/utils'

const controller = new AbortController()
const client = createPublicClient({
  chain: calibration,
  transport: withSignal(http('https://my-rpc.example.com'), controller.signal),
})