Attempting to subscribe in a go routine

This commit is contained in:
Brandon Watson 2023-09-22 16:06:58 -05:00
parent c4ebd5d6ff
commit 896bafe70b
2 changed files with 10 additions and 2 deletions

View File

@ -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
}

View File

@ -138,7 +138,8 @@ func (w *Websocket) Handshake(msg *message.Message) (resp *message.Message, err
// a connection is established by sending a message to the /meta/connect channel
func (w *Websocket) Connect(msg *message.Message) error {
go func() {
log.Fatal(w.readWorker())
err := w.readWorker()
log.Fatal(err)
}()
return w.SendMessage(msg)
}