import { HttpError } from "./HttpError.mjs"; //#region ../http/src/cancellable.d.ts /** * CancellableAsyncIterable — an AsyncIterable augmented with `.cancel()`, `.signal`, * and `.error`. Returned by Http.stream(). Use with `for await...of`. * * @example * const stream = http.stream('/chat', { method: 'POST', data: { messages } }); * for await (const chunk of stream) { * process(chunk); * } * // No try/catch needed — check .error after the loop: * if (stream.error) console.error('Stream failed:', stream.error.message); * * // Cancel from outside: * stream.cancel('component unmounted'); */ type CancellableAsyncIterable = AsyncIterable & { /** Abort the in-flight stream. Ends iteration silently. */cancel(reason?: string): void; /** The AbortSignal wired into this stream. */ readonly signal: AbortSignal; /** * Set after iteration ends if the stream terminated due to an error. * `null` on clean completion or cancellation. * * The generator never throws — errors are caught, stored here, and the * iteration ends. Check this value after your `for await` loop. */ readonly error: HttpError | null; }; /** * CancellablePromise — a Promise augmented with `.cancel()` and `.signal`. * * Usage: * const req = http.get('/users'); * req.cancel('leaving page'); * const { data, error } = await req; * // error.isAborted === true */ type CancellablePromise = Promise & { /** Abort the in-flight request. */cancel(reason?: string): void; /** The AbortSignal wired into this request. */ readonly signal: AbortSignal; }; /** * Wraps a factory that accepts an AbortSignal and returns a Promise. * Returns a CancellablePromise whose .cancel() triggers that signal. * * If an external signal is provided (e.g. from React Query or useEffect), * aborting *either* signal cancels the request. */ declare function makeCancellable(factory: (signal: AbortSignal) => Promise, externalSignal?: AbortSignal): CancellablePromise; //#endregion export { CancellableAsyncIterable, CancellablePromise, makeCancellable }; //# sourceMappingURL=cancellable.d.mts.map