amphp / byte-stream

A non-blocking stream abstraction for PHP based on Amp.
https://amphp.org/byte-stream
MIT License
363 stars 31 forks source link

Iterable readable streams #102

Closed trowski closed 1 year ago

trowski commented 1 year ago

This improves consuming a ReadableStream in a loop.

// Before
while (($chunk = $stream->read()) !== null) {
    // $chunk is a string
}

// After
foreach ($stream as $chunk) {
    // $chunk is a string
}