Skip to content

Commit

Permalink
Handle connection closed
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercr committed May 21, 2024
1 parent 4140828 commit f80e32b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions messagix/responsehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ResponseHandler struct {
}

var ErrTimeout = fmt.Errorf("timeout waiting for response")
var ErrConnectionClosed = fmt.Errorf("connection closed")
var ErrChannelNotFound = fmt.Errorf("channel not found for packet")

func (p *ResponseHandler) hasPacket(packetId uint16) bool {
Expand Down Expand Up @@ -103,6 +104,9 @@ func (p *ResponseHandler) waitForDetails(packetId uint16, channelType ChannelTyp

select {
case response := <-ch:
if response == nil {
return nil, ErrConnectionClosed
}
p.deleteDetails(packetId, channelType)
return response, nil
case <-time.After(packetTimeout):
Expand Down

0 comments on commit f80e32b

Please sign in to comment.