@worker-tools/stream-response
Version:
Fetch API Response objects made from async generators. Build streaming HTML responses or SSE with JS sugar.
22 lines (21 loc) • 1.46 kB
TypeScript
export declare type Awaitable<T> = T | Promise<T>;
export declare type ForAwaitable<T> = Iterable<T> | AsyncIterable<T>;
export type { ForAwaitable as ForOfAwaitable };
export declare const isIterable: <T>(x: unknown) => x is Iterable<T>;
export declare const isAsyncIterable: <T>(x: unknown) => x is AsyncIterable<T>;
export declare const isForAwaitable: <T>(x: unknown) => x is ForAwaitable<T>;
/**
* Alternates items from the first and second iterable in the output iterable, until either input runs out of items.
*/
export declare function interleave<X, Y>(xs: Iterable<X>, ys: Iterable<Y>): IterableIterator<X | Y>;
/**
* It's like interleave, but will flatten items of the second (async) iterable.
*/
export declare function aInterleaveFlattenSecond<X, Y>(xs: Iterable<X>, ys: Iterable<AsyncIterable<Y>>): AsyncIterableIterator<X | Y>;
export declare function map<A, B>(iterable: Iterable<A>, f: (a: A) => B): IterableIterator<B>;
export declare function aMap<A, B>(iterable: ForAwaitable<A>, f: (a: A) => Awaitable<B>): AsyncIterableIterator<B>;
export declare function join(iterable: Iterable<string>): string;
export declare function aJoin(iterable: ForAwaitable<string>): Promise<string>;
export declare function collect<T>(iterable: ForAwaitable<T>): Promise<T[]>;
export declare function promiseToAsyncIter<T>(promise: Promise<T>): AsyncIterableIterator<T>;
export declare function promiseToStream<T>(promise: Promise<T>): ReadableStream<T>;