Skip to content

Commit

Permalink
Huobi: Remove unnecessary funnelData
Browse files Browse the repository at this point in the history
  • Loading branch information
gbjk committed Dec 14, 2024
1 parent a8f81d3 commit 479095c
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions exchanges/huobi/huobi_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,46 +88,32 @@ func (h *HUOBI) WsConnect() error {
}
ctx := context.Background()

ch := make(chan []byte)
h.Websocket.Wg.Add(2)
go h.wsReadMsgs(ch)
go h.wsFunnelMsgs(h.Websocket.Conn, ch)
h.Websocket.Wg.Add(1)
go h.wsReadMsgs(h.Websocket.Conn)

h.Websocket.SetCanUseAuthenticatedEndpoints(false)
if h.IsWebsocketAuthenticationSupported() {
if err := h.wsAuthConnect(ctx); err != nil {
return fmt.Errorf("error authenticating websocket: %w", err)
}
h.Websocket.Wg.Add(1)
go h.wsFunnelMsgs(h.Websocket.AuthConn, ch)
go h.wsReadMsgs(h.Websocket.AuthConn)
}

return nil
}

// wsFunnelMsgs relays messages from a websocket to a channel for central processing
func (h *HUOBI) wsFunnelMsgs(s stream.Connection, ch chan []byte) {
// wsReadMsgs reads and processes messages from a websocket connection
func (h *HUOBI) wsReadMsgs(s stream.Connection) {
defer h.Websocket.Wg.Done()
for {
msg := s.ReadMessage()
if msg.Raw == nil {
return
}
ch <- msg.Raw
}
}

// wsReadMsgs receives messages from a message funnel and processes them
func (h *HUOBI) wsReadMsgs(ch chan []byte) {
defer h.Websocket.Wg.Done()
for {
select {
case <-h.Websocket.ShutdownC:
return
case msg := <-ch:
if err := h.wsHandleData(msg); err != nil {
h.Websocket.DataHandler <- err
}
if err := h.wsHandleData(msg.Raw); err != nil {
h.Websocket.DataHandler <- err
}
}
}
Expand Down

0 comments on commit 479095c

Please sign in to comment.