Re: "Reader" as alternative to Iterator

From: Date: Mon, 03 Jul 2017 15:50:30 +0000
Subject: Re: "Reader" as alternative to Iterator
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-99711@lists.php.net to get a copy of this message
On Mon, Jul 3, 2017 at 9:09 AM, Niklas Keller <me@kelunik.com> wrote: > > Hey Andreas, > > what you're trying to do here seems to be premature optimization. While you > save a bunch of method calls, your I/O will be the actual bottleneck there. > It's entirely fine to implement such logic in userland. I will let this stand unchallenged, until I have some reproducible data.. > > Amp has a similar interface for its streams, but those have only string|null > as types. If you want to allow all values, you either need a second method > or need to wrap all values in an object. > > http://amphp.org/byte-stream/#inputstream + > http://amphp.org/amp/iterators/#iterator-consumption This library looks interesting. It seems to do a lot more than I currently need, with its concurrency approach. I am a bit puzzled by the yield keyword in this code: while (($chunk = yield $inputStream->read()) !== null) { $buffer .= $chunk; } In my experience with generators so far, you either use yield for sending or for receiving. So either "yield $value;" or "$value = yield;" In this case it seems to do both. I assume this is to achieve the concurrency. (This is not an argument for or against anything, just an observation)

« previous php.internals (#99711) next »