Gui\Ipc\Receiver::waitMessage PHP Method

waitMessage() public method

Wait a message result
public waitMessage ( Stream $stdout, MessageInterface $message ) : mixed
$stdout React\Stream\Stream Stdout Stream
$message MessageInterface Command waiting result
return mixed The result
    public function waitMessage(Stream $stdout, MessageInterface $message)
    {
        $buffer = [];
        $this->waitingMessageId = $message->id;
        $this->isWaitingMessage = true;
        // Read the stdin until we get the message replied
        while ($this->isWaitingMessage) {
            $this->tick();
            usleep(1);
        }
        $stdout->resume();
        $result = $this->waitingMessageResult;
        $this->waitingMessageResult = null;
        foreach ($this->parseMessagesBuffer as $key => $message) {
            $this->parseNormal($message);
        }
        $this->parseMessagesBuffer = [];
        return $result;
    }

Usage Example

示例#1
0
 /**
  * Send a message and wait for the return
  *
  * @param MessageInterface $message
  *
  * @return mixed The return of the message
  */
 public function waitReturn(MessageInterface $message)
 {
     $this->processMessage($message);
     // Each message is terminated by the NULL character
     $this->sendLaterMessagesBuffer .= $this->getLazarusJson($message) . "";
     $this->writeOnStream();
     return $this->receiver->waitMessage($this->application->process->stdout, $message);
 }