Function: createAbortableOperation()
createAbortableOperation<
T>(operation: (signal:AbortSignal) =>Promise<T>,options:CombineSignalsOptions& {cleanup?: () =>void; }):Promise<T>
Defined in: shared/utils/abortUtils.ts:191
Executes an async operation with a composite abort signal and guaranteed cleanup.
Type Parametersโ
Tโ
T
Resolved value produced by the operation.
Parametersโ
operationโ
(signal: AbortSignal) => Promise<T>
Async function to execute with the composite signal.
optionsโ
CombineSignalsOptions & { cleanup?: () => void; } = {}
Signal configuration plus an optional cleanup callback.
Returnsโ
Promise<T>
Promise that resolves with the operation output.
Remarksโ
The generated signal honors every option supported by
CombineSignalsOptions. Provide a cleanup callback to release
resources regardless of whether the operation succeeds, fails, or the signal
aborts. If the cleanup throws, its error overrides any pending rejection from
the operation.
Exampleโ
import { logger } from "@app/services/logger";
const result = await createAbortableOperation(
    async (signal) => {
        const response = await fetch(url, { signal });
        return response.json();
    },
    {
        timeoutMs: 10_000,
        cleanup: () => logger.info("Operation cleaned up"),
    }
);
Throwsโ
Re-throws errors from the operation or cleanup callbacks.