From b51234cc825e160b7f671c8ffd80e445b76e0001 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Tue, 3 Sep 2024 17:31:30 +0100 Subject: [PATCH] Reduce allocs. --- conn.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/conn.go b/conn.go index 665ec2e..79b1dba 100644 --- a/conn.go +++ b/conn.go @@ -23,6 +23,7 @@ type Conn struct { interrupt context.Context pending *Stmt stmts []*Stmt + timer *time.Timer busy func(int) bool log func(xErrorCode, string) collation func(*Conn, string) @@ -394,10 +395,15 @@ func timeoutCallback(ctx context.Context, mod api.Module, pDB uint32, count, tmo time.Sleep(delay) return 1 } + if c.timer == nil { + c.timer = time.NewTimer(delay) + } else { + c.timer.Reset(delay) + } select { case <-c.interrupt.Done(): - // - case <-time.After(delay): + c.timer.Stop() + case <-c.timer.C: return 1 } }