當前位置: 首頁>>代碼示例>>PHP>>正文


PHP LoopInterface::tick方法代碼示例

本文整理匯總了PHP中React\EventLoop\LoopInterface::tick方法的典型用法代碼示例。如果您正苦於以下問題:PHP LoopInterface::tick方法的具體用法?PHP LoopInterface::tick怎麽用?PHP LoopInterface::tick使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在React\EventLoop\LoopInterface的用法示例。


在下文中一共展示了LoopInterface::tick方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testMapEndWithPendingItems

 public function testMapEndWithPendingItems()
 {
     $map = map(function ($n, callable $callback) {
         $this->eventLoop->nextTick(function () use($callback, $n) {
             $callback(null, 2 * $n);
         });
     }, ['concurrency' => 5]);
     $items = [];
     $ended = false;
     $map->on('data', function ($n) use(&$items) {
         $items[] = $n;
     });
     $map->on('end', function () use(&$ended) {
         $ended = true;
     });
     for ($i = 0; $i < 10; $i++) {
         $map->write($i);
     }
     $map->end();
     $this->assertFalse($ended);
     $this->assertEmpty($items);
     $this->eventLoop->tick();
     $this->assertTrue($ended);
     $this->assertSame(range(0, 18, 2), $items);
 }
開發者ID:joshdifabio,項目名稱:object-stream,代碼行數:25,代碼來源:FunctionsTest.php

示例2: testFutureTickFiresBeforeIO

 public function testFutureTickFiresBeforeIO()
 {
     $stream = $this->createStream();
     $this->loop->addWriteStream($stream, function () {
         echo 'stream' . PHP_EOL;
     });
     $this->loop->futureTick(function () {
         echo 'future-tick' . PHP_EOL;
     });
     $this->expectOutputString('future-tick' . PHP_EOL . 'stream' . PHP_EOL);
     $this->loop->tick();
 }
開發者ID:smileytechguy,項目名稱:nLine,代碼行數:12,代碼來源:AbstractLoopTest.php

示例3: wait

 /**
  * {@inheritdoc}
  */
 public function wait($unwrap = true)
 {
     if (null === $this->loop) {
         throw new \LogicException('You must set the loop before wait!');
     }
     while (HttpPromise::PENDING === $this->getState()) {
         $this->loop->tick();
     }
     if ($unwrap) {
         if (HttpPromise::REJECTED == $this->getState()) {
             throw $this->exception;
         }
         return $this->response;
     }
 }
開發者ID:php-http,項目名稱:react-adapter,代碼行數:18,代碼來源:Promise.php

示例4: waitFor

 protected function waitFor(PromiseInterface $promise, LoopInterface $loop)
 {
     $resolved = null;
     $exception = null;
     $promise->then(function ($c) use(&$resolved) {
         $resolved = $c;
     }, function ($error) use(&$exception) {
         $exception = $error;
     });
     while ($resolved === null && $exception === null) {
         $loop->tick();
     }
     if ($exception !== null) {
         throw $exception;
     }
     return $resolved;
 }
開發者ID:clue,項目名稱:bitbake-react,代碼行數:17,代碼來源:bootstrap.php

示例5: __invoke

 /**
  * @param array $requestArray
  * @return FutureArray
  */
 public function __invoke(array $requestArray)
 {
     $request = new Request($requestArray['http_method'], $requestArray['url'], $requestArray['headers'], $requestArray['body'], $requestArray['version']);
     $ready = false;
     $httpRequest = $this->requestFactory->create($request, $requestArray['client'], $this->httpClient, $this->loop);
     return new FutureArray($httpRequest->then(function (ResponseInterface $response) use(&$ready, $requestArray) {
         $ready = true;
         $responseArray = ['effective_url' => $requestArray['url'], 'body' => $response->getBody(), 'headers' => $response->getHeaders(), 'status' => $response->getStatusCode(), 'reason' => $response->getReasonPhrase(), 'version' => $response->getProtocolVersion()];
         return $responseArray;
     }, function ($error) use(&$ready) {
         $ready = true;
         return ['error' => $error];
     }), function () use(&$ready) {
         do {
             $this->loop->tick();
         } while (!$ready);
     });
 }
開發者ID:vucms,項目名稱:ReactGuzzleRing,代碼行數:22,代碼來源:HttpClientAdapter.php

示例6: __invoke

 /**
  * @param RequestInterface $request
  * @param array $options
  * @return Promise
  */
 public function __invoke(RequestInterface $request, array $options)
 {
     $ready = false;
     $promise = new Promise(function () use(&$ready) {
         do {
             $this->loop->tick();
         } while (!$ready);
     });
     $this->requestFactory->create($request, $options, $this->httpClient, $this->loop)->then(function (ResponseInterface $response) use(&$ready, $promise) {
         $ready = true;
         $promise->resolve($response);
         $this->invokeQueue();
     }, function ($error) use(&$ready, $promise) {
         $ready = true;
         $promise->reject($error);
         $this->invokeQueue();
     });
     return $promise;
 }
開發者ID:wyrihaximus,項目名稱:react-guzzle-psr7,代碼行數:24,代碼來源:HttpClientAdapter.php

示例7: tick

 /**
  * Perform a single iteration of the event loop.
  */
 public function tick()
 {
     $this->emit('tickStart');
     $this->loop->tick();
     $this->emit('tickDone');
 }
開發者ID:WyriHaximus,項目名稱:reactphp-event-loop-inspector,代碼行數:9,代碼來源:LoopDecorator.php

示例8: tick

 /**
  * Execute a single event loop iteration
  */
 public function tick()
 {
     $this->reactor->tick();
 }
開發者ID:daverandom,項目名稱:loopio,代碼行數:7,代碼來源:Loop.php

示例9: manyTicks

 private function manyTicks()
 {
     for ($i = 0; $i < 20; $i++) {
         $this->loop->tick();
     }
 }
開發者ID:pilat,項目名稱:daemonizer,代碼行數:6,代碼來源:MasterControllerTest.php


注:本文中的React\EventLoop\LoopInterface::tick方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。