summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org
diff options
context:
space:
mode:
authorLibravatar dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>2024-04-22 13:43:45 +0100
committerLibravatar GitHub <noreply@github.com>2024-04-22 13:43:45 +0100
commit62788aa1165496555f9bb1702cd0a57f6819c562 (patch)
treeb0a74b215bd934beeeb93f1d82864c45a6bdd421 /vendor/codeberg.org
parent[chore]: Bump github.com/miekg/dns from 1.1.58 to 1.1.59 (#2861) (diff)
downloadgotosocial-62788aa1165496555f9bb1702cd0a57f6819c562.tar.xz
[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] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Diffstat (limited to 'vendor/codeberg.org')
-rw-r--r--vendor/codeberg.org/gruf/go-mutexes/mutex_timeout.go60
1 files changed, 4 insertions, 56 deletions
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() }
}