phasync
Channels and messaging / QueueInterface

Interface

QueueInterface

A first-in first-out queue that coroutines may share.

Class synopsis#

interface QueueInterface extends \Countable, LockInterface {
    /* Methods */
    public QueueInterface::isEmpty(): bool
    public QueueInterface::enqueue(mixed $value): void
    public QueueInterface::tryDequeue(mixed &$value): bool
    public QueueInterface::tryPeek(mixed &$value): bool
}

Methods#

MethodDescription
isEmptyReturns true if the queue holds no values.
enqueueAdds $value at the end of the queue.
tryDequeueTakes the first value off the queue into $value, and returns whether there was one.
tryPeekCopies the first value of the queue into $value, without removing it, and returns whether there was one.

Examples#

Example 1
$queue = new phasync\Util\Queue();
$queue->enqueue('job');
if ($queue->tryDequeue($job)) {
    echo $job;          // job
}

See also#

  • QueueA first-in first-out queue whose operations take a lock, so coroutines may share it.