Created
October 25, 2023 07:39
-
-
Save wong2/6dec43547ff6295d8dd632e896515721 to your computer and use it in GitHub Desktop.
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
async function* streamAsyncIterable<T = unknown>(stream: ReadableStream<T>) { | |
const reader = stream.getReader() | |
try { | |
while (true) { | |
const { done, value } = await reader.read() | |
if (done) { | |
return | |
} | |
yield value | |
} | |
} finally { | |
reader.releaseLock() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment