Exemplo n.º 1
0
 public function next()
 {
     $coroutine = $this->_coroutine;
     if ($coroutine->valid()) {
         \Coroutine::resume($coroutine);
     }
 }
Exemplo n.º 2
0
 protected static function _wrap($coroutine)
 {
     $taskId = self::newTaskId();
     $coroutine = (function ($taskId, $coroutine) {
         $resp = (yield from $coroutine);
         \Coroutine::unregister($taskId);
     })($taskId, $coroutine);
     self::register($taskId, $coroutine);
     return $coroutine;
 }
Exemplo n.º 3
0
 public function multiCoroutine($taskId, $coroutine)
 {
     try {
         $resp = (yield from $coroutine);
         $this->_callRsp[] = $resp;
         if (count($this->_callRsp) == count($this->_callList)) {
             $this->executeCoroutine($this->_callRsp);
             $this->next();
         }
         \Coroutine::unregister($taskId);
     } catch (\Exception $e) {
         $this->executeCoroutine(null, $e);
         $this->next();
     }
 }
Exemplo n.º 4
0
/**
 * @return Generator
 * @throws \Steelbot\TelegramBotApi\Exception\TelegramBotApiException
 */
function botCoroutine() : \Generator
{
    $api = new Api(getenv('BOT_TOKEN'));
    $updateId = 1;
    printf("Waiting for updates ...\n");
    while (true) {
        // waiting for updates from telegram server
        /** @var Update[] $updates */
        $updates = (yield from $api->getUpdates($updateId));
        foreach ($updates as $update) {
            $method = processUpdate($update);
            if (is_object($method)) {
                yield from $api->execute($method);
            }
            $updateId = $update->updateId;
        }
    }
}
$coroutine = new Coroutine(botCoroutine());
$coroutine->done(null, function (\Throwable $exception) {
    echo "Exception catched:\n";
    echo "    Code: {$exception->getCode()}\n";
    echo "    Message: {$exception->getMessage()}\n";
    echo "    File: {$exception->getFile()}\n";
    echo "    Line: {$exception->getLine()}\n";
});
Loop\run();
Exemplo n.º 5
0
 public function next()
 {
     if ($this->_coroutine->valid()) {
         $coValue = $this->_coroutine->current();
         if (!$coValue instanceof \Client\Tcp) {
             \Coroutine::resume($this->_coroutine);
             $this->sleep();
             //当前协程不再监听读事件,则移除读事件
         }
     }
 }
Exemplo n.º 6
0
 public function next()
 {
     if ($this->_coroutine->valid()) {
         $coValue = $this->_coroutine->current();
         if (!$coValue instanceof \Client\Websocket) {
             \Coroutine::resume($this->_coroutine);
             $this->sleep();
             //当前协程不再监听读事件,则移除读事件
             return false;
         } else {
             return true;
         }
     }
 }
Exemplo n.º 7
0
 public static function release($client)
 {
     \Pool::release(static::TASK_QUEUE, $client);
     \Coroutine::next(static::TASK_QUEUE);
 }