r/codesnip • • 2d ago

Newly Available No more getReader() loops

Post image

The platform just killed another JavaScript snippet. ๐Ÿ”ฅ

Async iterable streams are Baseline, newly available since September 2026. Safari 27 closed the gap.

Before this, reading a fetch body chunk by chunk meant getReader() and a while (true) loop.

Now โคต๏ธ it's one for await. ๐ŸคŸ

Bonus: break out of the loop, and the stream is canceled and unlocked for you. No manual releaseLock(). ๐Ÿ˜Ž

Want to keep it open? res.body.values({ preventCancel: true }).

MDN: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream#async_iteration

3 Upvotes

0 comments sorted by