This is automatic generated document for things in Swow\Thannel class

Class Thannel

A queue that transfers serialized values between threads.

The capacity is a value count. Capacity 0 is unbuffered. Capacity -1 is unlimited. Values are serialized. A resource becomes 0. A closure cannot be passed. An unbuffered push waits for the consumer. In one OS thread the push does not return after the take. Use an unbuffered Thannel only across threads.

Methods

Method __construct

public function __construct ( int $capacity )

Create a Thannel. This method does not yield.

Param int $capacity capacity is -1 or between 0 and UINT32_MAX

Throws \ValueError when the capacity is out of range. Throws ThannelException when the Thannel is already constructed.

Method __debugInfo

public function __debugInfo ( ) : array

Return debug information.

Method __serialize

public function __serialize ( ) : array

Serialize the Thannel by shared object id.

The serialized form does not copy the queue.

Throws ThannelException when the Thannel is not constructed.

Method __unserialize

public function __unserialize ( array $data ) : void

Restore the Thannel from a shared object id.

Throws ThannelException when the data is invalid or the object is gone.

Method close

public function close ( ) : void

Close the queue.

Queued values stay available. A later push is rejected. A second close() does nothing.

Throws ThannelException when the queue is not constructed or close fails.

Method drain

public function drain ( ) : array

Remove all queued values without waiting.

Method getCapacity

public function getCapacity ( ) : int

Return the queue capacity.

Method getLength

public function getLength ( ) : int

Return the number of queued values.

Method getParkCount

public function getParkCount ( ) : int

Return the number of times a side parked.

Method getWakeCount

public function getWakeCount ( ) : int

Return the number of wakes that reached a waiter.

Method isClosed

public function isClosed ( ) : bool

Return true after the queue is closed.

Method isEmpty

public function isEmpty ( ) : bool

Return true when the queue has no values.

Method isFull

public function isFull ( ) : bool

Return true when the queue is full. An unbuffered Thannel is always full.

Method pop

public function pop ( int $timeout ) : mixed

Remove a value and unserialize it.

In a coroutine, this method suspends the current coroutine when the queue is empty.

context switching may happen here

Param int $timeout timeout in milliseconds, -1 waits forever

Throws ThannelException when the wait times out, the queue is closed and empty, or the value cannot be unserialized.

Method popMany

public function popMany ( int $max , int $timeout ) : array

Remove up to max values.

The call returns at least one value when the queue is not empty.

context switching may happen here

Param int $max maximum number of values to return Param int $timeout timeout in milliseconds, -1 waits forever

Returns array the values in queue order

Method push

public function push ( mixed $data , int $timeout ) : self

Serialize a value and add it to the queue.

In a coroutine, this method suspends the current coroutine when the queue is full. An unbuffered push in one OS thread does not return after the take. The timeout does not fire.

context switching may happen here

Param mixed $data value to serialize Param int $timeout timeout in milliseconds, -1 waits forever

Throws ThannelException on timeout (-110) or when the queue is closed (-9758) Throws \Exception when the value cannot be serialized

Method pushMany

public function pushMany ( array $values , int $timeout ) : int

Serialize a batch and push it as one unit.

The batch enters as a whole or not at all. In a coroutine, this method suspends the current coroutine when the batch does not fit.

context switching may happen here

Param array $values values to serialize Param int $timeout timeout in milliseconds, -1 waits forever

Returns int number of values pushed

Throws ThannelException on timeout, a closed queue, or an oversized batch

Method willBlock

public function willBlock ( ) : bool

Returns bool true when the queue is empty or full. An unbuffered Thannel always returns true.


Copyright 2022 the Swow contributors