/**
  * Stop thread after current works done and return
  */
 public function join()
 {
     if ($this->isExternal()) {
         $this->communicator->getLoop()->stop();
     } else {
         $this->callOnChild(__FUNCTION__, func_get_args());
     }
 }
 /**
  * Initialize your logic and do whatever you want external
  * @param ThreadCommunicator $communicator
  */
 public function InitializeExternal(ThreadCommunicator $communicator)
 {
     $communicator->getLoop()->addReadStream($this->stream, function ($stream) {
         $message = fgets($stream, 1024);
         //calling the EventEmiiter::emit() function on parent
         $this->callOnParent('emit', array('stream_message', array($message)));
     });
 }
 /**
  * Initialize your logic and do whatever you want external
  * @param ThreadCommunicator $communicator
  */
 public function InitializeExternal(ThreadCommunicator $communicator)
 {
     //save the loop to create fatal
     $this->loop = $communicator->getLoop();
     //we will kill the thread by exeptions and fatals
 }