If the channel is unbuffered, then one of the anonymous functions will not return. Goroutine and channel leak program.
If the channel has a buffer size greater than or equal to one, then both anonymous functions are returned. The resources used by the larynx and canals will be restored.
A single buffer size is sufficient to prevent leakage. The waitForOneOfTwoProcesses function gets one of the values ββsent to c . The second value sent to c is buffered in the channel (which is collected by the GC).
Another way to ensure goroutines return is to use non-blocking submission. Replace the lines c <- true with:
select { case c <- true: default: }
source share