Go Bridge-Channel: Difference between revisions
Jump to navigation
Jump to search
Line 2: | Line 2: | ||
* [[Go_Channels#The_bridge-channel|Channel Patterns]] | * [[Go_Channels#The_bridge-channel|Channel Patterns]] | ||
=Overview= | =Overview= | ||
<font color=darkkhaki>Concurrency in Go by Katherine Cox-Buday, Chapter 4. Concurrency Patterns in Go. The bridge-channel.</font> | <font color=darkkhaki>Concurrency in Go by Katherine Cox-Buday, Chapter 4. Concurrency Patterns in Go. The bridge-channel. | ||
You may find yourself wanting to consume values from a sequence of channels: | |||
<font size=-2> | |||
<-chan <-chan interface{} | |||
</font> | |||
A sequence of channels suggest an ordered write, albeit from different sources. | |||
One example might be a pipeline stage whose lifetime is intermittent. If we ensure that [[Go_Channels#Channel_Ownership|channels are owned by the goroutines that write to them]], every time a pipeline stage is restarted within a new goroutine, a new channel will be created. This means we'd effectively have a sequence of channels. | |||
<code>bridge()</code> is the function that restructures the channel of channels into a single channel. | |||
</font> |
Latest revision as of 23:27, 5 February 2024
Internal
Overview
Concurrency in Go by Katherine Cox-Buday, Chapter 4. Concurrency Patterns in Go. The bridge-channel.
You may find yourself wanting to consume values from a sequence of channels:
<-chan <-chan interface{}
A sequence of channels suggest an ordered write, albeit from different sources.
One example might be a pipeline stage whose lifetime is intermittent. If we ensure that channels are owned by the goroutines that write to them, every time a pipeline stage is restarted within a new goroutine, a new channel will be created. This means we'd effectively have a sequence of channels.
bridge()
is the function that restructures the channel of channels into a single channel.