This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A polyfill for `ReadableStream.protototype[Symbol.asyncIterator]`, | |
* aligning as closely as possible to the specification. | |
* | |
* @see https://streams.spec.whatwg.org/#rs-asynciterator | |
* @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#async_iteration | |
*/ | |
ReadableStream.prototype.values ??= function({ preventCancel = false } = {}) { | |
const reader = this.getReader(); | |
return { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Like ReadableStream.tee(), but for any async iterable. | |
* https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/tee | |
* | |
* See: MattiasBuelens/web-streams-polyfill#80 | |
*/ | |
/// <reference lib="esnext" /> | |
interface QueueNode<T> { | |
value: T; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function delay(): Promise<void> { | |
return new Promise((resolve) => setTimeout(resolve, 100)); | |
} | |
function abortableDelay(signal: AbortSignal): Promise<void> { | |
return new Promise((resolve, reject) => { | |
if (signal.aborted) { | |
return reject(new DOMException('Aborted', 'AbortError')); | |
} | |
const onAbort = () => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
ReadableStream as WhatWGReadableStream, | |
TransformStream as WhatWGTransformStream, | |
WritableStream as WhatWGWritableStream | |
} from 'whatwg-streams'; | |
export type ReadableStream<R> = WhatWGReadableStream<R>; | |
export const ReadableStream: typeof WhatWGReadableStream = (self as any).ReadableStream; | |
export type WritableStream<W> = WhatWGWritableStream<W>; |