/**
  * Encode the data given into binary message.
  * The message is send to the endpoint
  * @param array|mixed $data
  */
 public function writeAsync($data)
 {
     $this->dataBuffer .= $this->buffer->encodeMessage(serialize($data));
     if ($this->writeEvent === false) {
         $this->loop->addWriteStream($this->connection, function ($stream, LoopInterface $loop) {
             if (strlen($this->dataBuffer) > 0) {
                 $dataWritten = fwrite($stream, $this->dataBuffer);
                 $this->dataBuffer = substr($this->dataBuffer, $dataWritten);
                 if (strlen($this->dataBuffer) <= 0) {
                     $loop->removeWriteStream($stream);
                     $this->writeEvent = false;
                 }
             }
         });
         $this->writeEvent = true;
     }
 }