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 <[email protected]>
  • Loading branch information
rfyiamcool committed Dec 8, 2023
1 parent 01b0aae commit 5346582
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 @@ -455,13 +455,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 5346582

Please sign in to comment.