public function end() { if ($this->closed) { return; } $that = $this; $this->buffer->on('end', function () use($that) { $that->close(); }); $this->buffer->end(); }