From 62788aa1165496555f9bb1702cd0a57f6819c562 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 13:43:45 +0100 Subject: [chore]: Bump codeberg.org/gruf/go-mutexes from 1.4.0 to 1.4.1 (#2860) Bumps codeberg.org/gruf/go-mutexes from 1.4.0 to 1.4.1. --- updated-dependencies: - dependency-name: codeberg.org/gruf/go-mutexes dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .../codeberg.org/gruf/go-mutexes/mutex_timeout.go | 60 ++-------------------- 1 file changed, 4 insertions(+), 56 deletions(-) (limited to 'vendor/codeberg.org/gruf/go-mutexes') diff --git a/vendor/codeberg.org/gruf/go-mutexes/mutex_timeout.go b/vendor/codeberg.org/gruf/go-mutexes/mutex_timeout.go index 03bf0e389..e00444b64 100644 --- a/vendor/codeberg.org/gruf/go-mutexes/mutex_timeout.go +++ b/vendor/codeberg.org/gruf/go-mutexes/mutex_timeout.go @@ -1,7 +1,6 @@ package mutexes import ( - "sync" "time" ) @@ -78,60 +77,9 @@ func mutexTimeout(d time.Duration, unlock func(), fn func()) func() { return unlock } - // Acquire timer from pool - t := timerPool.Get().(*timer) + // Start timer to call fn. + t := time.AfterFunc(d, fn) - // Start the timer - go t.Start(d, fn) - - // Return func cancelling timeout, - // replacing Timeout in pool and - // finally unlocking mutex - return func() { - defer timerPool.Put(t) - t.Cancel() - unlock() - } -} - -// timerPool is the global &timer{} pool. -var timerPool = sync.Pool{ - New: func() interface{} { - t := time.NewTimer(time.Minute) - t.Stop() - return &timer{t: t, c: make(chan struct{})} - }, -} - -// timer represents a reusable cancellable timer. -type timer struct { - t *time.Timer - c chan struct{} -} - -// Start will start the timer with duration 'd', performing 'fn' on timeout. -func (t *timer) Start(d time.Duration, fn func()) { - t.t.Reset(d) - select { - // Timed out - case <-t.t.C: - fn() - - // Cancelled - case <-t.c: - } -} - -// Cancel will attempt to cancel the running timer. -func (t *timer) Cancel() { - select { - // cancel successful - case t.c <- struct{}{}: - if !t.t.Stop() { - <-t.t.C - } // stop timer - - // already stopped - default: - } + // Wrap unlock to stop mutex timer. + return func() { t.Stop(); unlock() } } -- cgit v1.2.3