Channels question

61 views
Skip to first unread message

Joe McGuckin

unread,
Sep 29, 2019, 5:04:15 PM9/29/19
to golang-nuts
If i have multiple goroutines listening on the same channel, then write something to the channel, will all goroutines receive the value, or only the ‘next’ available goroutine (as determined by the scheduler)

Thanks,

Joe

Kurtis Rader

unread,
Sep 29, 2019, 5:19:09 PM9/29/19
to Joe McGuckin, golang-nuts
On Sun, Sep 29, 2019 at 2:04 PM Joe McGuckin <mcgu...@gmail.com> wrote:
If i have multiple goroutines listening on the same channel, then write something to the channel, will all goroutines receive the value, or only the ‘next’ available goroutine (as determined by the scheduler)

Channels are queues: https://golang.org/ref/spec#Channel_types. They do not have fan-out semantics. Only one goroutine reading the channel will receive the next value.

--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
Reply all
Reply to author
Forward
0 new messages