Skip to content

Commit

Permalink
Cleaned up readReceiptWithTimeout function
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Ridgway committed Dec 1, 2020
1 parent cde1566 commit 4efe055
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,25 +478,19 @@ func (c *Conn) Send(destination, contentType string, body []byte, opts ...func(*
}

func readReceiptWithTimeout(request writeRequest, timeout time.Duration) error {
handle := func(response *frame.Frame) error {
if response.Command != frame.RECEIPT {
return newError(response)
}
return nil
}

if timeout <= 0 {
response := <-request.C
return handle(response)
var timeoutChan <-chan time.Time
if timeout > 0 {
timeoutChan = time.After(timeout)
}

timer := time.NewTimer(timeout)
select {
case <-timer.C:
case <-timeoutChan:
return ErrMsgReceiptTimeout
case response := <-request.C:
timer.Stop()
return handle(response)
if response.Command != frame.RECEIPT {
return newError(response)
}
return nil
}
}

Expand Down

0 comments on commit 4efe055

Please sign in to comment.