bitly / go-notify

a Go package to observe notable events in a decoupled fashion
238 stars 26 forks source link

Broadcast to subscribe chans in separate goroutines #2

Open jsimnz opened 9 years ago

jsimnz commented 9 years ago

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.

mreiferson commented 9 years ago

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.