React\Stream\Buffer::end PHP Method

end() public method

public end ( $data = null )
    public function end($data = null)
    {
        if (null !== $data) {
            $this->write($data);
        }
        $this->writable = false;
        if ($this->listening) {
            $this->on('full-drain', array($this, 'close'));
        } else {
            $this->close();
        }
    }

Usage Example

Example #1
0
 /**
  * @covers React\Stream\Buffer::end
  */
 public function testEndWithData()
 {
     $stream = fopen('php://temp', 'r+');
     $loop = $this->createWriteableLoopMock();
     $buffer = new Buffer($stream, $loop);
     $buffer->on('error', $this->expectCallableNever());
     $buffer->on('close', $this->expectCallableOnce());
     $buffer->end('final words');
     rewind($stream);
     $this->assertSame('final words', stream_get_contents($stream));
 }