go-notify icon indicating copy to clipboard operation
go-notify copied to clipboard

Broadcast to subscribe chans in separate goroutines

Open jsimnz opened this issue 9 years ago • 1 comments

When a Post is made for an event, a for-loop is used to broadcast the event to all the channel registered to that event.

But the send down the goroutine is a blocking call, and the channels are non-buffered, so it may block indefinately trying to send to the first channel, even though there are others also registered on that channel.

Basically all code that looks like this:

for _, outputChan := range outChans {
    outputChan <- data
}

Should look like this

for _, outputChan := range outChans {
    go outputChan <- data
}

PS. I know this repo hasnt been updated in 2 years, but this was a concern of mine while using it. I'm happy to submit a pull request if I know it'll get merged in.

jsimnz avatar Sep 18 '14 08:09 jsimnz

The end-user provides the channel to send to, it's entirely up to them to provide buffered channels so that the calls won't block.

mreiferson avatar Sep 18 '14 13:09 mreiferson