Go Bridge-Channel

From NovaOrdis Knowledge Base
Revision as of 23:27, 5 February 2024 by Ovidiu (talk | contribs) (→‎Overview)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.