Skip to content

Commit

Permalink
perf: reduce timer in write_control
Browse files Browse the repository at this point in the history
Signed-off-by: rfyiamcool <rfyiamcool@163.com>
  • Loading branch information
rfyiamcool authored and AlexVulaj committed Jan 23, 2024
1 parent cf50a3e commit d15aba1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,18 @@ func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) er
}
}

timer := time.NewTimer(d)
select {
case <-c.mu:
timer.Stop()
case <-timer.C:
return errWriteTimeout
default:
timer := time.NewTimer(d)
select {
case <-c.mu:
timer.Stop()
case <-timer.C:
return errWriteTimeout
}
}

defer func() { c.mu <- struct{}{} }()

c.writeErrMu.Lock()
Expand Down

0 comments on commit d15aba1

Please sign in to comment.