本文整理汇总了PHP中SplQueue::isEmpty方法的典型用法代码示例。如果您正苦于以下问题:PHP SplQueue::isEmpty方法的具体用法?PHP SplQueue::isEmpty怎么用?PHP SplQueue::isEmpty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplQueue
的用法示例。
在下文中一共展示了SplQueue::isEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startPendingTasks
/**
* Starts pending tasks end move them from the pendingQueue to the runningQueue
*/
private function startPendingTasks()
{
while (count($this->runningTasks) < $this->concurrencyLimit && !$this->pendingTasks->isEmpty()) {
/** @var TaskInterface $task */
$task = $this->pendingTasks->dequeue();
$task->start()->progress(function (Event $notification) {
$this->deferred->notify($notification);
})->always(function () use($task) {
$this->finishedTasks[] = $task;
$this->deferred->notify(new TaskFinishedEvent($this, $task));
});
$this->deferred->notify(new TaskStartedEvent($this, $task));
$this->runningTasks->enqueue($task);
}
}
示例2: pop
/**
* @coroutine
*
* @return \Generator
*
* @resolve \Icicle\Postgres\Connection
*/
private function pop() : \Generator
{
while (null !== $this->awaitable) {
try {
(yield $this->awaitable);
// Prevent simultaneous connection creation.
} catch (\Throwable $exception) {
// Ignore failure or cancellation of other operations.
}
}
if ($this->idle->isEmpty()) {
try {
if ($this->connections->count() >= $this->getMaxConnections()) {
// All possible connections busy, so wait until one becomes available.
$this->awaitable = new Delayed();
(yield $this->awaitable);
} else {
// Max connection count has not been reached, so open another connection.
$this->awaitable = new Coroutine($this->createConnection());
$this->addConnection((yield $this->awaitable));
}
} finally {
$this->awaitable = null;
}
}
// Shift a connection off the idle queue.
return $this->idle->shift();
}
示例3: close
public function close()
{
if (!$this->promises->isEmpty()) {
$this->promises->dequeue()->resolve();
} else {
$this->current--;
}
}
示例4: __invoke
public function __invoke($id, $service)
{
if ($this->middlewares->isEmpty()) {
return $service;
}
$method = $this->middlewares->dequeue();
return call_user_func($method, $this->container, new Next($this->container, $this->middlewares), $id, $service);
}
示例5: uncork
public function uncork()
{
if (!$this->corked) {
return;
}
while (!$this->corked && !$this->writeBuffer->isEmpty()) {
$this->doWrite(...$this->writeBuffer->dequeue());
}
}
示例6: tick
private function tick()
{
while (!$this->tick->isEmpty() && !$this->main->isFinished()) {
$task = $this->nextTask();
$task->run();
if ($task->isBlocked()) {
$this->addFutureTask($task);
}
}
}
示例7: getQuery
/**
* @inheritDoc
*/
public function getQuery(Driver $driver, $link)
{
if (!$this->pool->contains($link)) {
throw new \OutOfBoundsException(sprintf('Undefined %s in the pooling controller.', $driver->info($link)));
}
if (!$this->waiting->isEmpty()) {
return $this->waiting->dequeue();
}
$this->idle->enqueue($link);
}
示例8: processQueue
protected function processQueue()
{
$this->loop->addTimer($this->interval, function () {
if ($this->callQueue->isEmpty()) {
return;
}
$message = $this->callQueue->dequeue();
$data = ['function' => $message->getFunction(), 'args' => $message->getArgs(), 'errorResultCode' => $message->getErrorResultCode()];
$message->getDeferred()->resolve($data);
});
}
示例9: __invoke
/**
* @param Message $chapterCommand
* @param mixed $data
* @param ChapterLogger $chapterLogger
*/
public function __invoke(Message $chapterCommand, $data, ChapterLogger $chapterLogger)
{
$done = $this->done;
// No middleware remains; done
if ($this->queue->isEmpty()) {
return $done($chapterCommand, $data, $chapterLogger);
}
$stage = $this->queue->dequeue();
$executeStage = $this->executeStage;
return $executeStage($stage, $chapterCommand, $data, $chapterLogger, $this);
}
示例10: processQueue
protected function processQueue()
{
$this->loop->futureTick(function () {
if ($this->callQueue->isEmpty()) {
return;
}
$this->runningOperations++;
$message = $this->callQueue->dequeue();
$data = ['function' => $message->getFunction(), 'args' => $message->getArgs(), 'errorResultCode' => $message->getErrorResultCode()];
$message->getDeferred()->resolve($data);
});
}
示例11: run
private function run()
{
/** @var HttpServer $server */
$server = $this->container->get('http_server');
// Run async dispatcher
$server->getLoop()->addPeriodicTimer(Timer::MIN_INTERVAL, function (Timer $timer) {
if ($this->queue->isEmpty()) {
$timer->cancel();
return;
}
$event = $this->queue->dequeue();
$this->dispatch($event);
});
}
示例12: __invoke
/**
* @param Request $request
* @param Response $response
* @param callable[] ...$callables unshift callables (top priority)
* @return Response
*/
public function __invoke(Request $request, Response $response, ...$callables)
{
while ($callable = array_pop($callables)) {
$this->queue->unshift($callable);
}
if ($this->queue->isEmpty()) {
return $response;
}
$callable = $this->resolve($this->queue->dequeue());
if (is_callable($callable)) {
return call_user_func($callable, $request, $response, $this);
} else {
throw new \UnexpectedValueException();
}
}
示例13: endRead
private function endRead()
{
$this->readEnded = true;
if ($this->readBuffer->isEmpty()) {
$this->ensureEndEmitted();
}
}
示例14: processStateQueue
/**
* @param null $lastPublicationId
*/
private function processStateQueue($lastPublicationId = null)
{
if ($lastPublicationId !== null) {
// create an array of pub ids
// if we can't find the lastPublicationId in the queue
// then we are going to assume it was before our time
$pubIds = [];
/** @var EventMessage $msg */
foreach ($this->pauseQueue as $msg) {
$pubIds[] = $msg->getPublicationId();
}
if (!in_array($lastPublicationId, $pubIds)) {
$lastPublicationId = null;
}
}
while (!$this->pauseQueue->isEmpty()) {
$msg = $this->pauseQueue->dequeue();
if ($lastPublicationId === null) {
$this->sendEventMessage($msg);
}
if ($lastPublicationId == $msg->getPublicationId()) {
$lastPublicationId = null;
}
}
}
示例15: render
/**
* Process the given queue of template files and
* returns the generated output.
*
* @param string $file
*
* @return string
* @throws RendererException
*/
public function render(string $file) : string
{
if ($this->rendering) {
throw new RendererException("Cannot call render() inside templates.");
}
$this->rendering = true;
$this->queue->enqueue($file);
$this->sections()->declare('content');
ob_start();
while (!$this->queue->isEmpty()) {
$file = $this->engine->path($this->queue->dequeue());
if (!file_exists($file)) {
throw new \RuntimeException("Cannot find file: {$file}");
}
require $file;
$this->sections()->populate('content', ob_get_contents(), 'replace');
ob_clean();
if ($this->extended) {
$this->extended = false;
}
}
ob_end_clean();
$this->rendering = false;
return $this->sections()->fetch('content');
}