Manual
Channels and messaging
Pass values between coroutines: channels, queues and publishers.
Introduction#
phasync::channel returns two objects, not one: a read end (ReadChannelInterface) and a write end (WriteChannelInterface). There is no Channel class. Give the write end to the coroutines that produce values and the read end to those that consume them; a read waits until a value is written, and when every write end is gone the reader sees the channel close. phasync::publisher is the one-to-many form: every subscriber gets every value. Queue is a plain FIFO buffer for when no coroutine needs to wait.
Guides#
- Channels – Pass values between coroutines.
Examples#
- All examples of this topic – 11 with their output.
Reference#
phasync::channel– Creates a channel and returns its two ends in $read and $write.phasync::publisher– Creates a publisher: what is written to $publisher is delivered to every subscription of $subscribers.ChannelException– A channel operation failed: it was written to after it was closed, or the wait looked like a deadlock.ReadChannelInterface– The reading end of a channel: values written to the channel arrive here in the order they were written.SubscriberInterface– A subscription to a publisher: a reading end that receives every message published after it was made.SubscribersInterface– The subscription point of a publisher: each call to subscribe() makes a reader that receives every later message.Queue– A first-in first-out queue whose operations take a lock, so coroutines may share it.QueueInterface– A first-in first-out queue that coroutines may share.WriteChannelInterface– The writing end of a channel: write() sends a value to the readers of the channel.