function abortableAsyncIterable
abortableAsyncIterable<T>(p: AsyncIterable<T>,signal: AbortSignal): AsyncGenerator<T>Make AsyncIterable abortable with the given signal.
Examples
Example 1
Example 1
import { abortableAsyncIterable, delay, } from "@std/async"; const p = async function* () { yield "Hello"; await delay(1000); yield "World"; }; const c = new AbortController(); setTimeout(() => c.abort(), 100); // Below throws `DOMException` after 100 ms // and items become `["Hello"]` const items: string[] = []; for await (const item of abortableAsyncIterable(p(), c.signal)) { items.push(item); }
Type Parameters
TParameters
p: AsyncIterable<T>signal: AbortSignal