phasync\Internal\ChannelUnbuffered final class

Documentation

This is a highly optimized implementation of a bi-directional channel for communication between coroutines running in the same memory space without threading. It is not meant to be used directly since it has no protection against deadlocks. Instead channels should be created via phasync::channel().

The implementation reaches around 500 000 reads and 500 000 writes between a pair of coroutines on an AMD Ryzen 7 2700X.

Inheritance

Implements: phasync\Internal\ChannelBackendInterface IteratorAggregate phasync\SelectableInterface Traversable phasync\WriteChannelInterface phasync\ReadChannelInterface

Constants (3)

NameValue
READY 0
BLOCKING_READS 1
BLOCKING_WRITES 2

Properties (8)

private static array $waiting

Waiting fibers in all channels are stored in a static array, because

private int $id
private bool $closed
private mixed $value
private ?Fiber $creatingFiber
private object $flag
private int $state

Channels are either blocking reads or writes. When the channel is in

private ?Fiber $receiver

When a channel reads a message from a blocked writer, it temporarily

Methods (16)

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Source

src/Internal/ChannelUnbuffered.php:19-253