本文整理汇总了PHP中React\EventLoop\LoopInterface::stop方法的典型用法代码示例。如果您正苦于以下问题:PHP LoopInterface::stop方法的具体用法?PHP LoopInterface::stop怎么用?PHP LoopInterface::stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类React\EventLoop\LoopInterface
的用法示例。
在下文中一共展示了LoopInterface::stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write
/**
* Listen for exit command and terminate
* the event loop
*
* @param string $data
* @return void
*/
public function write($data)
{
if (trim($data) === self::EXIT_CMD) {
$this->loop->stop();
$this->close();
}
}
示例2: stop
/**
* Stops shell
*/
public function stop()
{
if (!$this->running) {
return;
}
$this->loop->stop();
$this->running = false;
}
示例3: stop
/**
* {@inheritdoc}
*/
public function stop()
{
if (null !== $this->loop) {
$this->loop->stop();
$this->httpServer->removeAllListeners();
$this->httpServer = null;
$this->socketServer->shutdown();
$this->socketServer = null;
$this->loop = null;
}
}
示例4: fanout
/**
* Create a queue with fanout exchange.
*
* @param string $exchange
* @param string $queue
*
* @return PromiseInterface
*/
public function fanout($exchange, $queue)
{
if (!isset($this->queues[$queue])) {
$this->queues[$queue] = $this->connect()->then(function (Channel $channel) use($exchange, $queue) {
return \React\Promise\all([$channel, $channel->queueDeclare($queue), $channel->exchangeDeclare($exchange, 'fanout'), $channel->queueBind($queue, $exchange)]);
}, function (Exception $exception) {
$this->loop->stop();
throw new AsyncMessagingException(sprintf('Could not create channel and exchange: %s on line %s in file %s', $exception->getMessage(), $exception->getLine(), $exception->getFile()), 0, $exception);
});
}
return $this->queues[$queue];
}
示例5: terminate
public function terminate()
{
$this->loop->stop();
$this->daemon->terminate();
// @codeCoverageIgnoreStart
if (!defined('PHPUNIT_TEST')) {
define('PHPUNIT_TEST', false);
}
// @codeCoverageIgnoreEnd
if (!PHPUNIT_TEST) {
die;
}
}
示例6: consumeMessage
/**
* @param callable $callback
*
* @return void
*/
protected function consumeMessage(callable $callback)
{
$this->channelFactory->fanout($this->exchange, $this->channel)->then(function ($r) use($callback) {
/** @var Channel $channel */
$channel = $r[0];
return $channel->consume(function (Message $message) use($callback) {
$data = json_decode($message->content, true);
$callback($this->serializer->deserialize(null, $data));
}, $this->channel, '', false, true);
}, function (Exception $exception) {
$this->loop->stop();
throw new AsyncMessagingException(sprintf('Could not consume message: %s on line %s in file %s', $exception->getMessage(), $exception->getLine(), $exception->getFile()), 0, $exception);
});
}
示例7: stop
public function stop()
{
$this->peersInbound->close();
$this->peersOutbound->close();
$this->loop->stop();
$this->db->stop();
}
示例8: sendTasks
/**
* Action time for master! Send tasks `to-do` for workers and go to sleep.
* Also decide when to stop server/loop.
*/
public function sendTasks()
{
if (!$this->wait) {
if (count($this->tasks) > 0) {
// Get task name to do.
$task = current($this->tasks);
$taskName = $task->getName();
array_shift($this->tasks);
$this->informer->startTask($taskName);
if ($task->isOnce()) {
$task->run(new Context(null, null, $this->input, $this->output));
$this->informer->endTask();
} else {
$this->tasksToDo = [];
foreach ($this->servers as $serverName => $server) {
if ($task->runOnServer($serverName)) {
$env = isset($this->environments[$serverName]) ? $this->environments[$serverName] : ($this->environments[$serverName] = new Environment());
if (count($task->getOnlyForStage()) > 0 && (!$env->has('stages') || !$task->runForStages($env->get('stages')))) {
continue;
}
$this->informer->onServer($serverName);
$this->tasksToDo[$serverName] = $taskName;
}
}
// Inform all workers what tasks they need to do.
$taskToDoStorage = new ArrayStorage();
$taskToDoStorage->push($this->tasksToDo);
$this->pure->setStorage('tasks_to_do', $taskToDoStorage);
$this->wait = true;
}
} else {
$this->loop->stop();
}
}
}
示例9: 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;
}
示例10: sendTasks
/**
* Action time for master! Send tasks `to-do` for workers and go to sleep.
* Also decide when to stop server/loop.
*/
public function sendTasks()
{
if (!$this->wait) {
if (count($this->tasks) > 0) {
// Get task name to do.
$task = current($this->tasks);
$taskName = $task->getName();
array_shift($this->tasks);
$this->informer->startTask($taskName);
if ($task->isOnce()) {
$task->run(new Context($this->localhost, $this->localEnv, $this->input, $this->output));
$this->informer->endTask();
} else {
$this->tasksToDo = [];
foreach ($this->servers as $serverName => $server) {
if ($task->isOnServer($serverName)) {
if (!isset($this->environments[$serverName])) {
$this->environments[$serverName] = new Environment();
}
// Start task on $serverName.
$this->tasksToDo[$serverName] = $taskName;
}
}
// Inform all workers what tasks they need to do.
$taskToDoStorage = new ArrayStorage();
$taskToDoStorage->push($this->tasksToDo);
$this->pure->setStorage('tasks_to_do', $taskToDoStorage);
$this->wait = true;
}
} else {
$this->loop->stop();
}
}
}
示例11: stop
/**
* Disconnect and stop the event loop
*/
public function stop()
{
$this->wsClient->close();
$this->ariClient->onClose(function () {
$this->eventLoop->stop();
});
}
示例12: consume
public function consume($topic, $channel, $payload)
{
if (!count($this->messages)) {
return;
}
try {
if (!$this->exception) {
$this->checkMessage($topic, $channel, $payload);
}
} catch (\PHPUnit_Framework_AssertionFailedError $e) {
$this->exception = $e;
}
if (count($this->messages) == 0) {
$this->loop->stop();
}
}
示例13: publishMessage
/**
* @param QueueMessage $message
*
* @return void
*/
protected function publishMessage(QueueMessage $message)
{
$this->channelFactory->fanout($this->exchange, $this->channel)->then(function ($r) use($message) {
/** @var Channel $channel */
$channel = $r[0];
return \React\Promise\all([$channel->publish(json_encode($this->serializer->serialize($message)), [], $this->exchange)]);
}, function (Exception $exception) {
$this->loop->stop();
throw new AsyncMessagingException(sprintf('Could not publish message: %s on line %s in file %s', $exception->getMessage(), $exception->getLine(), $exception->getFile()), 0, $exception);
})->then(function () {
$this->loop->stop();
}, function (Exception $exception) {
$this->loop->stop();
var_dump(sprintf('Could not publish message: %s on line %s in file %s', $exception->getMessage(), $exception->getLine(), $exception->getFile()));
});
$this->loop->run();
}
示例14: stop
/**
* Calls {@link eventLoop}'s stop() method.
*/
public function stop()
{
if ($this->stopTimer) {
$this->stopTimer->cancel();
$this->stopTimer = null;
}
$this->eventLoop->stop();
}
示例15: checkSigterm
/**
* Checks if the SIGTERM is presente in the server.
*/
protected function checkSigterm()
{
if ($this->sigterm) {
$this->loop->stop();
$this->socket->shutdown();
$this->output->writeln('The Foreman Processor has been stopped.');
}
}