From 43c45904398f76044ae2c01cb7a66a388bcc16d3 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 20 Jan 2024 11:16:54 -0500 Subject: [PATCH] refactor: use time.Ticker --- storage/locker.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/storage/locker.go b/storage/locker.go index 5368e03..99a0e0d 100644 --- a/storage/locker.go +++ b/storage/locker.go @@ -80,13 +80,17 @@ func (l *Lock) Lock(ctx context.Context, requestUnlock func()) error { } go func() { + ticker := time.NewTicker(l.holderPollInterval) + defer ticker.Stop() + for { select { case <-l.stopHolderPoll: return - case <-time.After(l.holderPollInterval): + case <-ticker.C: requested, err := l.lockRecord.IsReleaseRequested(db) - if err == nil { + if err != nil { + // Handle error continue }