2017-07-03 17:50 GMT+02:00 Andreas Hennings <andr...@dqxtech.net>: > On Mon, Jul 3, 2017 at 9:09 AM, Niklas Keller <m...@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. >
Indeed, it can do both at the same time. > I assume this is to achieve the concurrency. Not exactly, it "outputs" a promise and "inputs" the resolution value or exception once that promise resolves. Regards, Niklas