本文整理汇总了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);
}
示例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();
}
示例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;
}
}
示例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;
}
示例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);
});
}
示例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;
}
示例7: tick
/**
* Perform a single iteration of the event loop.
*/
public function tick()
{
$this->emit('tickStart');
$this->loop->tick();
$this->emit('tickDone');
}
示例8: tick
/**
* Execute a single event loop iteration
*/
public function tick()
{
$this->reactor->tick();
}
示例9: manyTicks
private function manyTicks()
{
for ($i = 0; $i < 20; $i++) {
$this->loop->tick();
}
}