本文整理汇总了PHP中SplQueue::push方法的典型用法代码示例。如果您正苦于以下问题:PHP SplQueue::push方法的具体用法?PHP SplQueue::push怎么用?PHP SplQueue::push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplQueue
的用法示例。
在下文中一共展示了SplQueue::push方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: writeItem
/**
* {@inheritdoc}
*/
public function writeItem(array $item)
{
$this->queue->push($item);
if (count($this->queue) >= $this->size) {
$this->flush();
}
}
示例2: add
/**
* Добавляем задачу в очередь
*
* @param mixed $data данные запроса
* @param string $correlation id сообщения
*
* @return Producer
*/
public function add($data = null, $correlation = null)
{
$Message = $this->_message($data, ['reply_to' => $this->_cbQueue, 'correlation_id' => $correlation ?: String::uuid()]);
$this->_collerations[$Message->get('correlation_id')] = time();
$this->_Messages->push($Message);
return $this;
}
示例3: solve
/**
* Solve missionaries and cannibals problem.
*
* @return bool
*/
public function solve()
{
$initialState = new State(3, 3, 0, 0, 'left');
$initialNode = new Node($initialState, null, null);
if ($initialNode->state->isGoalState()) {
$this->displayNodeInfo($initialNode);
return true;
}
$queue = new SplQueue();
$queue->push($initialNode);
$explored = [];
while (true) {
if ($queue->isEmpty()) {
return false;
//nothing found
}
$node = $queue->pop();
$this->displayNodeInfo($node);
array_push($explored, $node->state);
if ($node->state->isGoalState()) {
return true;
}
//get all action and states available
$states = $node->state->getNextStates();
foreach ($states as $stateNode) {
if (!$stateNode->state->isValidState()) {
continue;
}
if (!in_array($stateNode->state, $explored)) {
$queue->push($stateNode);
}
}
}
}
示例4: execute
/**
* {@inheritdoc}
*/
public function execute(Immediate $immediate)
{
if (!$this->immediates->contains($immediate)) {
$this->queue->push($immediate);
$this->immediates->attach($immediate);
}
}
示例5: push
/**
* 压入 middleware
*
* @param callbale $callbale 一般为回调函数
* @return \Lime\Middleware
*/
public function push($callbale)
{
if ($callbale instanceof \Closure) {
$callbale = $this->bindToThis($callbale);
}
$this->queue->push($callbale);
return $this;
}
示例6: testProvideQueueAsStartPoint
/**
* @covers Gliph\Traversal\DepthFirst::traverse
*/
public function testProvideQueueAsStartPoint()
{
extract($this->v);
$queue = new \SplQueue();
$queue->push($a);
$queue->push($e);
$this->g->addVertex($a);
$this->g->addVertex($e);
DepthFirst::traverse($this->g, new DepthFirstNoOpVisitor(), $queue);
}
示例7: testForValidValues
public function testForValidValues()
{
$var = new \SplQueue();
$var->push(1);
$var->push(2);
$var->push(3);
$data = new VariableWrapper(get_class($var), $var);
$result = $this->inspector->get($data);
$this->assertInstanceOf('Ladybug\\Plugin\\Extra\\Type\\CollectionType', $result);
$this->assertCount(3, $result);
}
示例8: iterate_queue_with_mode
function iterate_queue_with_mode($mode)
{
$x = new SplQueue();
$x->setIteratorMode($mode);
$x->push(1);
$x->push(2);
$x->push(3);
foreach ($x as $y) {
var_dump($y);
}
var_dump(count($x));
}
示例9: send
/**
* @coroutine
*
* @param string $data
* @param float|int $timeout
* @param bool $end
*
* @return \Generator
*
* @resolve int Number of bytes written to the file.
*
* @throws \Icicle\Stream\Exception\UnwritableException
*/
protected function send(string $data, float $timeout, bool $end = false) : \Generator
{
if (!$this->isWritable()) {
throw new UnwritableException('The file is no longer writable.');
}
if ($this->queue->isEmpty()) {
$awaitable = $this->push($data);
} else {
$awaitable = $this->queue->top();
$awaitable = $awaitable->then(function () use($data) {
return $this->push($data);
});
}
$this->queue->push($awaitable);
if ($end) {
$this->writable = false;
}
if ($timeout) {
$awaitable = $awaitable->timeout($timeout);
}
$this->poll->listen();
try {
$result = (yield $awaitable);
} catch (\Exception $exception) {
$this->close();
throw $exception;
} finally {
if ($end) {
$this->close();
}
$this->poll->done();
}
return $result;
}
示例10: send
/**
* @coroutine
*
* @param string $data
* @param float|int $timeout
* @param bool $end
*
* @return \Generator
*
* @resolve int Number of bytes written to the stream.
*
* @throws \Icicle\Stream\Exception\UnwritableException If the stream is no longer writable.
*/
protected function send(string $data, float $timeout = 0, bool $end = false) : \Generator
{
if (!$this->isWritable()) {
throw new UnwritableException('The stream is no longer writable.');
}
$this->buffer->push($data);
if (null !== $this->delayed && !$this->buffer->isEmpty()) {
$delayed = $this->delayed;
$this->delayed = null;
$delayed->resolve($this->remove());
}
if ($end) {
if ($this->buffer->isEmpty()) {
$this->free();
} else {
$this->writable = false;
}
}
if (0 !== $this->hwm && $this->buffer->getLength() > $this->hwm) {
$awaitable = new Delayed($this->onCancelled = $this->onCancelled ?: function () {
$this->free();
});
$this->queue->push($awaitable);
if ($timeout) {
$awaitable = $awaitable->timeout($timeout);
}
(yield $awaitable);
}
return strlen($data);
}
示例11: doQuery
/**
* @param string $sql
* @param callable $callback
*/
protected function doQuery($sql, callable $callback)
{
//remove from idle pool
$db = array_pop($this->idle_pool);
/**
* @var \mysqli $mysqli
*/
$mysqli = $db['object'];
for ($i = 0; $i < 2; $i++) {
$result = $mysqli->query($sql, MYSQLI_ASYNC);
if ($result === false) {
if ($mysqli->errno == 2013 or $mysqli->errno == 2006) {
$mysqli->close();
$r = $mysqli->connect();
if ($r === true) {
continue;
}
} else {
#echo "server exception. \n";
$this->connection_num--;
$this->wait_queue->push(array('sql' => $sql, 'callback' => $callback));
return;
}
}
break;
}
$task['sql'] = $sql;
$task['callback'] = $callback;
$task['mysql'] = $db;
//join to work pool
$this->work_pool[$db['socket']] = $task;
}
示例12: push
public function push($value)
{
if (!$value instanceof Task) {
throw new \InvalidArgumentException("TaskQueue expects instance of Task only");
}
parent::push($value);
}
示例13: doQuery
/**
* @param string $sql
* @param callable $callback
*/
protected function doQuery($sql, callable $callback)
{
deQueue:
//remove from idle pool
$db = array_pop($this->idle_pool);
/**
* @var \mysqli $mysqli
*/
$mysqli = $db['object'];
if ($this->haveSwooleAsyncMySQL) {
$result = swoole_mysql_query($mysqli, $sql, array($this, 'onSQLReady'));
} else {
$result = $mysqli->query($sql, MYSQLI_ASYNC);
}
if ($result === false) {
if ($mysqli->errno == 2013 or $mysqli->errno == 2006 or isset($mysqli->_errno) and $mysqli->_errno == 2006) {
$mysqli->close();
unset($mysqli);
$this->connection_num--;
//创建连接成功
if ($this->createConnection() === 0) {
goto deQueue;
}
} else {
$this->wait_queue->push(array('sql' => $sql, 'callback' => $callback));
return;
}
}
$task['sql'] = $sql;
$task['callback'] = $callback;
$task['mysql'] = $db;
//join to work pool
$this->work_pool[$db['socket']] = $task;
}
示例14: receive
/**
* Receive a value from the channel.
*
* Be careful when you may receive null values: you need to change the EOF param accordingly!
*
* @param mixed $eof The EOF value, a channel will return this value if it has been closed without an error.
* @return mixed The received value.
*
* @throws \Throwable Fails if the channel has been closed with an error.
*/
public function receive($eof = null) : Awaitable
{
if (!$this->buffer) {
while ($this->senders && !$this->senders->isEmpty()) {
$subscription = $this->senders->dequeue();
if ($subscription->active) {
$subscription->resolve($subscription->data);
return new Success($subscription->data);
}
}
} elseif (!$this->buffer->isEmpty()) {
while ($this->senders && !$this->senders->isEmpty()) {
$subscription = $this->senders->dequeue();
if ($subscription->active) {
$subscription->resolve($subscription->data);
$this->buffer->push($subscription->data);
}
}
return new Success($this->buffer->dequeue());
}
if ($this->closed instanceof \Throwable) {
return new Failure($this->closed);
} elseif ($this->closed) {
return new Success($eof);
}
if (!$this->receivers) {
$this->receivers = new \SplQueue();
}
$this->receivers->enqueue($subscription = new ChannelSubscription($eof));
return $subscription;
}
示例15: push
/**
* @param \Icicle\Postgres\Connection $connection
*
* @throws \Icicle\Exception\InvalidArgumentError
*/
private function push(Connection $connection)
{
if (!isset($this->connections[$connection])) {
throw new InvalidArgumentError('Connection is not part of this pool');
}
$this->idle->push($connection);
if ($this->awaitable instanceof Delayed) {
$this->awaitable->resolve($connection);
}
}