Go OR-Done-Channel Pattern: Difference between revisions
Jump to navigation
Jump to search
Line 3: | Line 3: | ||
=Overview= | =Overview= | ||
Reading from a channel until the channel is closed can be expressed with <code>range</code>: | |||
<syntaxhighlight lang='go'> | |||
for v := range c { | |||
// do something with the channel value, we exit the loop automatically when the channel is closed | |||
... | |||
} | |||
</syntaxhighlight> |
Revision as of 22:08, 5 February 2024
Internal
Overview
Reading from a channel until the channel is closed can be expressed with range
:
for v := range c {
// do something with the channel value, we exit the loop automatically when the channel is closed
...
}