final class Channel (View source)

Unbuffered Channels


An unbuffered channel will block on calls to Channel::send() until there is a receiver, and block on calls to Channel::recv() until there is a sender. This means an unbuffered channel is not only a way to share data among tasks but also a simple method of synchronization.

An unbuffered channel is the fastest way to share data among tasks, requiring the least copying.

Buffered Channels


A buffered channel will not block on calls to Channel::send() until capacity is reached, calls to

Constants

Infinite

Constant for Infinitely Buffered

Methods

__construct(int|null $capacity = null)

Shall make an anonymous unbuffered channel Shall make an anonymous buffered channel with the given capacity

static Channel
make(string $name, int|null $capacity = null)

Shall make an unbuffered channel with the given name Shall make a buffered channel with the given name and capacity

static Channel
open(string $name)

Shall open the channel with the given name

void
send(mixed $value)

Shall send the given value on this channel

mixed
recv()

Shall recv a value from this channel

void
close()

Shall close this channel

string
__toString()

Returns name of channel

Details

__construct(int|null $capacity = null)

Shall make an anonymous unbuffered channel Shall make an anonymous buffered channel with the given capacity

Parameters

int|null $capacity

May be Channel::Infinite or a positive integer

static Channel make(string $name, int|null $capacity = null)

Shall make an unbuffered channel with the given name Shall make a buffered channel with the given name and capacity

Parameters

string $name

The name of the channel.

int|null $capacity

May be Channel::Infinite or a positive integer

Return Value

Channel

Exceptions

Existence

static Channel open(string $name)

Shall open the channel with the given name

Parameters

string $name

Return Value

Channel

Exceptions

Existence

void send(mixed $value)

Shall send the given value on this channel

Parameters

mixed $value

Return Value

void

Exceptions

Closed
IllegalValue

mixed recv()

Shall recv a value from this channel

Return Value

mixed

Exceptions

Closed

void close()

Shall close this channel

Return Value

void

Exceptions

Closed

string __toString()

Returns name of channel

Return Value

string