SwooleMailbox
in package
implements
Mailbox
Swoole-backed mailbox using a Swoole\Coroutine\Channel for message passing.
"Unbounded" configs are physically capped by the channel at 65,536 slots (exposed via SwooleMailbox::$effectiveCapacity). Admission is truthful: every push result is inspected, and a full channel surfaces the configured overflow strategy — for unbounded configs that strategy is ThrowException, so hitting the physical cap throws MailboxOverflowException instead of silently losing the message.
On close(), remaining messages are drained from the channel into an internal SplQueue backup so they can still be dequeued after the channel is closed.
Note: Swoole Channel pop(0.0) blocks indefinitely because 0.0 is treated as falsy, falling back to the default -1 timeout. We use a tiny positive epsilon (0.001s) for non-blocking operations instead.
Tags
Table of Contents
Interfaces
Properties
- $effectiveCapacity : int
- The real slot count of the underlying channel, also for "unbounded" configs.
Methods
- __construct() : mixed
- close() : void
- Close the mailbox. Subsequent enqueue() calls return EnqueueResult::Dropped without raising. Blocked dequeueBlocking() calls return null once the mailbox drains (closed-and-empty).
- count() : int
- dequeue() : T|null
- dequeueBlocking() : T
- enqueue() : EnqueueResult
- isClosed() : bool
- isEmpty() : bool
- isFull() : bool
Properties
$effectiveCapacity read-only
The real slot count of the underlying channel, also for "unbounded" configs.
public
int
$effectiveCapacity
Methods
__construct()
public
__construct(MailboxConfig $config) : mixed
Parameters
- $config : MailboxConfig
close()
Close the mailbox. Subsequent enqueue() calls return EnqueueResult::Dropped without raising. Blocked dequeueBlocking() calls return null once the mailbox drains (closed-and-empty).
public
close() : void
Idempotent — calling close() on an already-closed mailbox is a no-op.
Required by Plan 5 (graceful shutdown). Without close(), the actor's message loop has no way to wake up cleanly when the system stops.
Attributes
- #[Override]
count()
public
count() : int
Attributes
- #[Override]
Return values
intdequeue()
public
dequeue() : T|null
Attributes
- #[Override]
Return values
T|nulldequeueBlocking()
public
dequeueBlocking(Duration $timeout) : T
Parameters
- $timeout : Duration
Tags
Attributes
- #[Override]
Return values
Tenqueue()
public
enqueue(T $message) : EnqueueResult
Parameters
- $message : T
Tags
Attributes
- #[NoDiscard]
- #[Override]
Return values
EnqueueResultisClosed()
public
isClosed() : bool
Attributes
- #[Override]
Return values
boolisEmpty()
public
isEmpty() : bool
Attributes
- #[Override]
Return values
boolisFull()
public
isFull() : bool
Attributes
- #[Override]