breaking out of a select statement when all channels are closed

前端 未结 5 1453
后悔当初
后悔当初 2021-01-30 00:48

I have two goroutines independently producing data, each sending it to a channel. In my main goroutine, I\'d like to consume each of these outputs as they come in, but don\'t ca

5条回答
  •  感动是毒
    2021-01-30 01:39

    I wrote a package which provides a function to solve this problem (among several others):

    https://github.com/eapache/channels

    https://godoc.org/github.com/eapache/channels

    Check out the Multiplex function. It uses reflection to scale to an arbitrary number of input channels.

提交回复
热议问题