kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
17 wiersze
342 B
TypeScript
17 wiersze
342 B
TypeScript
![]() |
import { type ReadableStream } from 'stream/web'
|
||
|
|
||
|
export async function* streamAsyncIterable(stream: ReadableStream) {
|
||
|
const reader = stream.getReader()
|
||
|
try {
|
||
|
while (true) {
|
||
|
const { done, value } = await reader.read()
|
||
|
if (done) {
|
||
|
return
|
||
|
}
|
||
|
yield value
|
||
|
}
|
||
|
} finally {
|
||
|
reader.releaseLock()
|
||
|
}
|
||
|
}
|