export function readStream( stream: ReadableStream, controls: { onRead: (value: T) => void; onDone: () => void; }, ) { let reader = stream.getReader(); function process({ done, value }: ReadableStreamReadResult) { if (value) { controls.onRead(value); } if (done) { controls.onDone(); } else { reader.read().then(process); } } reader.read().then(process); }