本文整理汇总了PHP中React\EventLoop\LoopInterface::nextTick方法的典型用法代码示例。如果您正苦于以下问题:PHP LoopInterface::nextTick方法的具体用法?PHP LoopInterface::nextTick怎么用?PHP LoopInterface::nextTick使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类React\EventLoop\LoopInterface
的用法示例。
在下文中一共展示了LoopInterface::nextTick方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
/**
* {@inheritdoc}
*/
protected function setUp()
{
$app = new Container();
$app->instance('config', new Repository());
(new EventServiceProvider($app))->register();
(new AmiServiceProvider($app))->register();
$this->loop = $app[LoopInterface::class];
$this->loop->nextTick(function () {
if (!$this->running) {
$this->loop->stop();
}
});
$this->stream = $app[Stream::class];
$this->events = $app['events'];
$this->app = $app;
}
示例2: 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);
}
示例3: run
/**
* Start the event reactor and assume program flow control
*
* @param callable $onStart Optional callback to invoke immediately upon reactor start
*/
public function run(callable $onStart = null)
{
if ($onStart) {
$this->reactor->nextTick($onStart);
}
$this->reactor->run();
}
示例4: nextTick
/**
* Schedule a callback to be invoked on the next tick of the event loop.
*
* Callbacks are guaranteed to be executed in the order they are enqueued,
* before any timer or stream events.
*
* @param callable $listener The callback to invoke.
*/
public function nextTick(callable $listener)
{
$this->emit('nextTick', [$listener]);
return $this->loop->nextTick(function (LoopInterface $loop) use($listener) {
$this->emit('nextTickTick', [$listener]);
$listener($this);
});
}
示例5: testFutureTickEventGeneratedByNextTick
public function testFutureTickEventGeneratedByNextTick()
{
$stream = $this->createStream();
$this->loop->nextTick(function () {
$this->loop->futureTick(function () {
echo 'future-tick' . PHP_EOL;
});
});
$this->expectOutputString('future-tick' . PHP_EOL);
$this->loop->run();
}
示例6: continueFlow
/**
* Continues the given flow.
*
* @param ReactFlow $flow
* @param Packet $packet
*/
private function continueFlow(ReactFlow $flow, Packet $packet)
{
try {
$response = $flow->next($packet);
} catch (\Exception $e) {
$this->emitError($e);
return;
}
if ($response !== null) {
if ($this->stream->getBuffer()->listening) {
$this->sendingFlows[] = $flow;
} else {
$this->stream->write($response);
$this->writtenFlow = $flow;
}
} elseif ($flow->isFinished()) {
$this->loop->nextTick(function () use($flow) {
$this->finishFlow($flow);
});
}
}
示例7: computeId
/**
* @return \React\Promise\Promise|PromiseInterface
*/
public function computeId()
{
$deferred = new Deferred();
$this->loop->nextTick($this->doCompute($deferred));
return $deferred->promise();
}