Skip to main content

Function: createAbortableOperation()

createAbortableOperation<T>(operation: (signal: AbortSignal) => Promise<T>, options: CombineSignalsOptions & { cleanup?: () => void; }): Promise<T>

Defined in: shared/utils/abortUtils.ts:156

Creates an operation that can be aborted and provides cleanup.

Type Parametersโ€‹

Tโ€‹

T

Parametersโ€‹

operationโ€‹

(signal: AbortSignal) => Promise<T>

Async function that performs the operation

optionsโ€‹

CombineSignalsOptions & { cleanup?: () => void; } = {}

Configuration options

Returnsโ€‹

Promise<T>

Promise that resolves to the operation result

Remarksโ€‹

Wraps an async operation with abort support and automatic cleanup. The operation function receives an AbortSignal and should check it periodically for cancellation.

Exampleโ€‹

const result = await createAbortableOperation(
async (signal) => {
const response = await fetch(url, { signal });
return response.json();
},
{
timeoutMs: 10000,
cleanup: () => console.log("Operation cleaned up"),
}
);