Clue\React\Redis\StreamingClient::__construct PHP Method

__construct() public method

public __construct ( Stream $stream, Clue\Redis\Protocol\Parser\ParserInterface $parser = null, Clue\Redis\Protocol\Serializer\SerializerInterface $serializer = null )
$stream React\Stream\Stream
$parser Clue\Redis\Protocol\Parser\ParserInterface
$serializer Clue\Redis\Protocol\Serializer\SerializerInterface
    public function __construct(Stream $stream, ParserInterface $parser = null, SerializerInterface $serializer = null)
    {
        if ($parser === null || $serializer === null) {
            $factory = new ProtocolFactory();
            if ($parser === null) {
                $parser = $factory->createResponseParser();
            }
            if ($serializer === null) {
                $serializer = $factory->createSerializer();
            }
        }
        $that = $this;
        $stream->on('data', function ($chunk) use($parser, $that) {
            try {
                $models = $parser->pushIncoming($chunk);
            } catch (ParserException $error) {
                $that->emit('error', array($error));
                $that->close();
                return;
            }
            foreach ($models as $data) {
                try {
                    $that->handleMessage($data);
                } catch (UnderflowException $error) {
                    $that->emit('error', array($error));
                    $that->close();
                    return;
                }
            }
        });
        $stream->on('close', array($this, 'close'));
        $this->stream = $stream;
        $this->parser = $parser;
        $this->serializer = $serializer;
    }