Interface
WriteChannelInterface
The writing end of a channel: write() sends a value to the readers of the channel.
Introduction#
On an unbuffered channel write() returns when a reader has taken the value; on a buffered one it returns at once while the buffer has room, and waits when it is full. Dropping the last reference to an end closes the channel, so a reader sees the end when the writer is gone.
Class synopsis#
interface WriteChannelInterface extends SelectableInterface {
/* Methods */
public WriteChannelInterface::activate(): void
public WriteChannelInterface::close(): void
public WriteChannelInterface::isClosed(): bool
public WriteChannelInterface::write(mixed $value, float $timeout = PHP_FLOAT_MAX): void
public WriteChannelInterface::isWritable(): bool
}Methods#
| Method | Description |
|---|---|
activate | Switches off the deadlock check of the channel. |
close | Closes the channel, for both ends. |
isClosed | Returns true if the channel has been closed. |
write | Sends a value, and waits while the channel cannot take it: for a reader on an unbuffered channel, for room on a full buffer. |
isWritable | Returns true if the channel is open, so a write is accepted. |
Examples#
phasync::run(function () {
phasync::channel($read, $write, 3);
phasync::go(function () use ($write) {
foreach ([1, 2, 3] as $number) {
$write->write($number);
}
$write->close();
});
foreach ($read as $number) {
echo $number, "\n";
}
});See also#
phasync::channelCreates a channel and returns its two ends in$readand$write.ReadChannelInterfaceThe reading end of a channel: values written to the channel arrive here in the order they were written.