Go OR-Done-Channel Pattern

From NovaOrdis Knowledge Base
Revision as of 22:09, 5 February 2024 by Ovidiu (talk | contribs) (→‎Overview)
Jump to navigation Jump to search

Internal

Overview

Reading from a channel until the channel is closed can be done by ranging over a channel:

for v := range c {
  // do something with the channel value, we exit the loop automatically when the channel is closed
  ...
}