React\Stream\Buffer::write PHP Method

write() public method

public write ( $data )
    public function write($data)
    {
        if (!$this->writable) {
            return;
        }
        $this->data .= $data;
        if (!$this->listening && $this->data !== '') {
            $this->listening = true;
            $this->loop->addWriteStream($this->stream, array($this, 'handleWrite'));
        }
        return !isset($this->data[$this->softLimit - 1]);
    }

Usage Example

Example #1
0
 /**
  * @covers React\Stream\Buffer::handleWrite
  * @covers React\Stream\Buffer::errorHandler
  */
 public function testError()
 {
     $stream = null;
     $loop = $this->createWriteableLoopMock();
     $error = null;
     $buffer = new Buffer($stream, $loop);
     $buffer->on('error', function ($message) use(&$error) {
         $error = $message;
     });
     $buffer->write('Attempting to write to bad stream');
     $this->assertInstanceOf('Exception', $error);
     $this->assertSame('Tried to write to closed or invalid stream.', $error->getMessage());
 }
All Usage Examples Of React\Stream\Buffer::write