Channel
in package
A channel allows coroutines to communicate by sending and polling values in an FIFO stream.
Tags
Table of Contents
- $state : EmptyChannelState|SendingChannelState|ReceivingChannelState
- __construct() : mixed
- getReceiveQueueSize() : int
- getSendQueueSize() : int
- receive() : Generator
- Receive a value from the channel.
- sendAndWait() : Generator
- Sends a value to the channel, and wait until the value is received by the other side.
- sendWithoutWait() : void
- Send a value to the channel without waiting for a receiver.
- tryReceiveOr() : T|U
- Try to receive a value from the channel if there is a sender waiting.
- trySend() : bool
- Try to send a value to the channel if there is a receive waiting.
Properties
$state
private
EmptyChannelState|SendingChannelState|ReceivingChannelState
$state
Methods
__construct()
public
__construct() : mixed
Return values
mixed —getReceiveQueueSize()
public
getReceiveQueueSize() : int
Return values
int —getSendQueueSize()
public
getSendQueueSize() : int
Return values
int —receive()
Receive a value from the channel.
public
receive() : Generator
Waits for a sender if there is currently no sender waiting.
Return values
Generator —sendAndWait()
Sends a value to the channel, and wait until the value is received by the other side.
public
sendAndWait(T $value) : Generator
Parameters
- $value : T
Return values
Generator —sendWithoutWait()
Send a value to the channel without waiting for a receiver.
public
sendWithoutWait(T $value) : void
This method always returns immediately.
It is equivalent to calling Await::g2c($channel->sendAndWait($value))
.
Parameters
- $value : T
Return values
void —tryReceiveOr()
Try to receive a value from the channel if there is a sender waiting.
public
tryReceiveOr(U $default) : T|U
Returns $default
if there is no sender waiting.
Parameters
- $default : U
Tags
Return values
T|U —trySend()
Try to send a value to the channel if there is a receive waiting.
public
trySend(T $value) : bool
Returns whether the value successfully sent.
Parameters
- $value : T