Skip to content

Commit b51234c

Browse files
committed
Reduce allocs.
1 parent cf7b89d commit b51234c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

conn.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type Conn struct {
2323
interrupt context.Context
2424
pending *Stmt
2525
stmts []*Stmt
26+
timer *time.Timer
2627
busy func(int) bool
2728
log func(xErrorCode, string)
2829
collation func(*Conn, string)
@@ -394,10 +395,15 @@ func timeoutCallback(ctx context.Context, mod api.Module, pDB uint32, count, tmo
394395
time.Sleep(delay)
395396
return 1
396397
}
398+
if c.timer == nil {
399+
c.timer = time.NewTimer(delay)
400+
} else {
401+
c.timer.Reset(delay)
402+
}
397403
select {
398404
case <-c.interrupt.Done():
399-
//
400-
case <-time.After(delay):
405+
c.timer.Stop()
406+
case <-c.timer.C:
401407
return 1
402408
}
403409
}

0 commit comments

Comments
 (0)