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 itscausechain. 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
waitForTransactionReceiptswallows polling errors, so on awithSignalclient it runs until its timeout. Wrap receipt waits in abortable instead.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Description |
|---|---|
transport extends Transport |
The transport to wrap. |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
transport |
transport |
- |
signal |
AbortSignal | undefined |
The signal to abort requests. The transport is returned as is when undefined. |
Returns
Section titled “Returns”transport
The wrapped transport.
Example
Section titled “Example”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),
})