Attempting to subscribe in a go routine
This commit is contained in:
@ -32,11 +32,18 @@ func NewSubscription(chanel string, unsub Unsubscriber, authToken string, msgCh
|
||||
|
||||
func (s *Subscription) OnMessage(onMessage func(channel string, msg message.Data)) error {
|
||||
var inMsg *message.Message
|
||||
go s.StartMessageLoop(inMsg, onMessage)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Subscription) StartMessageLoop(inMsg *message.Message, callback func(channel string, msg message.Data)) error {
|
||||
for inMsg = range s.msgCh {
|
||||
if inMsg.GetError() != nil {
|
||||
|
||||
return inMsg.GetError()
|
||||
}
|
||||
onMessage(inMsg.Channel, inMsg.Data)
|
||||
callback(inMsg.Channel, inMsg.Data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user