amphp / byte-stream

A non-blocking stream abstraction for PHP based on Amp.

Home Page:https://amphp.org/byte-stream

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

InputStreamChain

ostrolucky opened this issue · comments

I needed to combine output of two input streams while not leaking null from previous stream. I abandoned this idea after all, but code is already written and wonder if you would be interested in me to contribute it here? Usage is like following.

public function testInputStreamChain()
{
    $chain = new InputStreamChain(new InMemoryStream('foo'), new InMemoryStream(null), new InMemoryStream('bar'));

    self::assertEquals('foo', wait($chain->read()));
    self::assertEquals(null, wait($chain->read()));
    self::assertEquals('bar', wait($chain->read()));
}

@ostrolucky Sorry for not responding yet, sounds fine to me.

The second call to read() should not return null. Consecutive calls to read() should return 'foo', 'bar', then null.

That's discutable, but I have found that impossible to solve anyway in my implementation. Source can be found at https://github.com/ostrolucky/stdinho/blob/cfb4735e5037575eeb1b5275f890a2b3cd19473e/src/Stream/InputStreamChain.php