/** * @packageDocumentation * * @example * * ```js * import { abortableSource } from 'abortable-iterator' * * async function main () { * // An example function that creates an async iterator that yields an increasing * // number every x milliseconds and NEVER ENDS! * const asyncCounter = async function * (start, delay) { * let i = start * while (true) { * yield new Promise(resolve => setTimeout(() => resolve(i++), delay)) * } * } * * // Create a counter that'll yield numbers from 0 upwards every second * const everySecond = asyncCounter(0, 1000) * * // Make everySecond abortable! * const controller = new AbortController() * const abortableEverySecond = abortableSource(everySecond, controller.signal) * * // Abort after 5 seconds * setTimeout(() => controller.abort(), 5000) * * try { * // Start the iteration, which will throw after 5 seconds when it is aborted * for await (const n of abortableEverySecond) { * console.log(n) * } * } catch (err) { * if (err.code === 'ERR_ABORTED') { * // Expected - all ok :D * } else { * throw err * } * } * } * * main() * ``` */ import { AbortError } from './abort-error.js'; import type { Duplex, Source, Sink } from 'it-stream-types'; export interface Options { onReturnError?(err: Error): void; onAbort?(source: Source): void; abortMessage?: string; abortCode?: string; abortName?: string; returnOnAbort?: boolean; } /** * Wrap an iterator to make it abortable, allow cleanup when aborted via onAbort */ export declare function abortableSource(source: Source, signal: AbortSignal, options?: Options): AsyncGenerator; export declare function abortableSink>(sink: Sink, R>, signal: AbortSignal, options?: Options): Sink, R>; export declare function abortableDuplex>(duplex: Duplex, Source, RSink>, signal: AbortSignal, options?: Options): Duplex, Source, RSink>; export { AbortError }; export { abortableSink as abortableTransform }; //# sourceMappingURL=index.d.ts.map