-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Subscribe methods does not return channel #28
Comments
This is currently the way to use subscriptions with rec := make(chan []string)
go func() {
select {
case ls = <-rec:
t.Logf("Got: %v\n", ls)
}
}()
go consumer.Subscribe(rec, "channel") The problem I tried to solve was setting up the select before attempting to subscribe (subscribe is a blocking function) and that was the way that seemed right at the time. Obviously I'm no expert and I'm sure things could be better, what do you think of this? (untested). var rec chan []string
var err error
if rec, err = consumer.SubscribeNonBlocking("channel"); err != nil {
t.Logf("Failed: %q", err)
}
go func() {
select {
case ls = <-rec:
t.Logf("Got: %v\n", ls)
}
}() Do you have any suggestions? |
I just started learning Go and this question appeared, because I didn't see any point in passing this channel instead of returning new instance from subscribe function. But I'm very new to Go, so I don't know how things here should be done. Best regards, Vyacheslav On Mon, Jun 9, 2014 at 5:21 PM, Carlos Nieto [email protected]
|
@Termina1 Here is a simple use case : you might want to use that channel for multiple subscribers. |
I wonder, why this methods (subscribe, psubscribe) do not return channels, but you should pass one as an argument? Isn't a creation of this channel a boilerplate code?
The text was updated successfully, but these errors were encountered: