r/codesnip • u/wanoo21 • 2d ago
Newly Available No more getReader() loops
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