Wait for a frame from the server

@return array
@throws \Exception
426453
protected function waitFrame()
    {
        $frameType = $this->input->readOctet();
        $channel = $this->input->readShort();
        $size = $this->input->readLong();
        $payload = $this->input->read($size);

        $ch = $this->input->readOctet();
        if ($ch != 0xCE) {
            throw new \Exception(
                sprintf(
                    'Framing error, unexpected byte: %x', $ch
                )
            );
        }

        return array($frameType, $channel, $payload);
    }
407816
public function listen(): Promise
    {
        return call(function () {
            while (null !== ($chunk = yield $this->stream->read())) {
                foreach ($this->onNewFrameCallables as $newFrameCallable) {
                    $newFrameCallable($this->transformChunk($chunk));
                }
            }
        });
    }
591157
public function onReady()
    {
        $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();

        $params = [];
        foreach (range(0, 100) as $i) {
            $params[] = 'myset' . $i;
            $params[] = 'value' . $i;
        }
        $params[] = function ($redis) {
            $params = [
                function ($redis) {
                    D('Count: ' . count($redis->result[1]) . '; Next: ' . $redis->result[0]);
                }
            ];

            $cbEnd = function ($redis, $scan) {
                D('Full scan end!');
            };

            // test 1
            // $this->redis->scan(...$params);

            // test 2
            $this->redis->autoscan('scan', $params, $cbEnd, 50);
        };
        $this->redis->mset(...$params);
    }
665372
private function connect()
    {
        $headers = [];
        if ($this->lastId) {
            $headers['Last-Event-ID'] = $this->lastId;
        }

        $this->response = $this->client->request('GET', $this->url, [
            'stream' => true,
            'headers' => $headers,
        ]);

        if ($this->response->getStatusCode() == 204) {
            throw new RuntimeException('Server forbid connection retry by responding 204 status code.');
        }
    }
1356658
public function wait()
    {
        $pid = $this->getSupervisorPid();
        if (!empty($pid)) {
            while ($this->isProcessRunning($pid)) {
                sleep(1);
            }
        }
    }
971014
public function wait($names = null) {
        $namesArr = !isset($names) ? array_keys($this->pids) : (array) $names;
        foreach ($namesArr as $name) {
            if (!isset($this->pids[$name])) {
                continue;
            }
            pcntl_waitpid($this->pids[$name], $status);
            unset($this->pids[$name]);
        }
        $result = $this->Storage->get($this->key, $namesArr);
        $this->Storage->del($this->key, $namesArr);
        return is_string($names) ? $result[$names] : $result;
    }
918673
def _send_and_wait(self, **kwargs):
        
        frame_id = self.next_frame_id
        kwargs.update(dict(frame_id=frame_id))
        self._send(**kwargs)
        timeout = datetime.now() + const.RX_TIMEOUT
        while datetime.now() < timeout:
            try:
                frame = self._rx_frames.pop(frame_id)
                raise_if_error(frame)
                return frame
            except KeyError:
                sleep(0.1)
                continue
        _LOGGER.exception(
            "Did not receive response within configured timeout period.")
        raise exceptions.ZigBeeResponseTimeout()
1117974
public function serve() {

        $this->logger->notice("Start serving request");

        $parameters_object = new Parameters($this->capabilities, $this->methods, $this->errors, $this->logger, $this->protocol);

        try {

            $this->logger->debug("Received payload: ".$this->payload);

            $payload = $this->uncan($this->payload);

            $this->logger->debug("Decoded payload", (array) $payload);

            if ( $this->protocol == self::XMLRPC ) $result = XmlProcessor::process($payload, $parameters_object, $this->logger);

            else if ( $this->protocol == self::JSONRPC ) $result = JsonProcessor::process($payload, $parameters_object, $this->logger);

            else throw new Exception('Invalid or unsupported RPC protocol');

        } catch (RpcException $re) {

            return $this->can($re, true);

        } catch (Exception $e) {

            throw $e;

        }

        return $this->can($result, false);

    }
902519
public function onReady()
    {
        $this->redis = \PHPDaemon\Clients\Redis\Pool::getInstance();

        $this->redis->multi(function ($multi) {
            // "OK"
            D('start multi: ' . $multi->result);

            $multi->set('test1', 'value1', function ($redis) use ($multi) {
                // "QUEUED"
                D('in multi 1: ' . $redis->result);

                $this->redis->set('test1', 'value1-new', function ($redis) {
                    // "OK", not "QUEUED"
                    D('out multi 1: ' . $redis->result);
                });

                setTimeout(function ($timer) use ($multi) {
                    // "QUEUED"
                    $multi->set('test2', 'value2', function ($redis) use ($multi) {
                        D('in multi 2: ' . $redis->result);

                        $multi->exec(function ($redis) {
                            D('exec');
                            D($redis->result);
                        });
                    });
                    $timer->free();
                }, 2e5);
            });
        });
    }
7373
public function after() {
		if($this->_handle_ajax == true)
		{
			if($this->request->is_ajax())
			{
				$return = array();

				if(RD::has_messages() == false)
				{
					$return['status'] = 'success';
					$return['response'] = [''];
				}
				else if(RD::get_current(RD::ERROR) != null)
				{
					$return['status'] = 'error';
					$return['errors'] = RD::get_current(RD::ERROR);
				}
				else if(RD::get_current(array(RD::SUCCESS, RD::INFO)) != null)
				{
					$return['status'] = 'success';
					$return['response'] = RD::get_current(array(RD::SUCCESS, RD::INFO, RD::WARNING));
				}
				else
				{
					$return['status'] = 'success';
					$return['response'] = RD::get_current();
				}

				$this->response->headers('Content-Type', 'application/json');
				$this->response->body(json_encode($return));
			}
			else
			{
				//otherwise flash the messages so they can be used on the next page load
				if(RD::has_messages())
					RD::persist();

				parent::after();
			}
		}
		else
			parent::after();
	}
878036
protected function executeNextWaitingRequest()
    {
        if (($this->numberOfParallelRequests === 0 || count($this->runningRequests) < $this->numberOfParallelRequests)
            && count($this->waitingRequests) > 0
        ) {
            $this->executeRequest(reset($this->waitingRequests));
        }
        return $this;
    }
1332687
public function execute()
    {
        $locator = $this->element->getLocator();
        if (null === $this->callback) {
            throw new WebDriver_Exception("Wait callback is undefined for element '{$locator}''");
        }
        for ($i = 0; $i < $this->timeout; $i++) {
            if (call_user_func($this->callback, $this->element())) {
                return $this;
            }
            sleep(1);
        }
        $message = "Provided state of element '{$locator}' is not reached after timeout";
        $message = ($this->errorMessage == null) ? $message : "{$message} with error: {$this->errorMessage}";
        throw new WebDriver_Exception($message);
    }
992636
protected function getReceivingFrame(): Frame
    {
        $current = $this->getCurrentFrame();

        if ($current->isComplete()) {
            if ($current->isFinal()) {
                throw new PayloadException('Payload cannot receive data: it is already complete');
            } else {
                $this->frames[] = $current = $this->getFrame();
            }
        }

        return $current;
    }
1194613
public function fetchWaitingWorker()
    {
        $count = count($this->waitingList);
        for ($i = 0; $i < $count; $i++) {
            $worker = array_shift($this->waitingList);
            if ($worker->isValid() && $worker->isReady()) {
                return $worker;
            }
        }

        $this->ready = false;

        return null;
    }
354803
public function waitForReload($callback = null, $seconds = null)
    {
        $token = Str::random();

        $this->driver->executeScript("window['{$token}'] = {};");

        if ($callback) {
            $callback($this);
        }

        return $this->waitUsing($seconds, 100, function () use ($token) {
            return $this->driver->executeScript("return typeof window['{$token}'] === 'undefined';");
        }, 'Waited %s seconds for page reload.');
    }
1296390
public function serverResponse()
    {
        try
        {
            $this->generator->serverResponse();
        }
        catch(\Exception $exception)
        {
            // Handle server generating image response exception
            if($this->handleExceptions)
            {
                if(is_string($this->handleExceptions))
                {
                    Debugger::log($exception->getMessage(), $this->handleExceptions);
                }
                else
                {
                    Debugger::log($exception, 'palette');
                }
            }
            else
            {
                throw $exception;
            }

            // Return fallback image on exception if fallback image is configured
            $fallbackImage = $this->generator->getFallbackImage();

            if($fallbackImage)
            {
                $paletteQuery = preg_replace('/.*@(.*)/', $fallbackImage . '@$1', $_GET['imageQuery']);

                $picture  = $this->generator->loadPicture($paletteQuery);
                $savePath = $this->generator->getPath($picture);

                if(!file_exists($savePath))
                {
                    $picture->save($savePath);
                }

                $picture->output();
            }
        }
    }
303346
public function onReady()
    {
        \PHPDaemon\Servers\WebSocket\Pool::getInstance()->addRoute(
            '/sockjs',
            function ($client) {
                return new SimpleRoute($client, $this);
            }
        );
    }