Skip to content

Instantly share code, notes, and snippets.

@dasl-
Created November 3, 2020 21:43
Show Gist options
  • Save dasl-/cc3d114b28be78c4abfc40539a02ca58 to your computer and use it in GitHub Desktop.
Save dasl-/cc3d114b28be78c4abfc40539a02ca58 to your computer and use it in GitHub Desktop.
diff --git a/go/pools/numbered.go b/go/pools/numbered.go
index ef4e3ea30..48b497807 100644
--- a/go/pools/numbered.go
+++ b/go/pools/numbered.go
@@ -134,30 +134,31 @@ func (nu *Numbered) Put(id int64) {
nu.mu.Lock()
defer nu.mu.Unlock()
if nw, ok := nu.resources[id]; ok {
nw.inUse = false
nw.purpose = ""
nw.timeUsed = time.Now()
}
}
// GetAll returns the list of all resources in the pool.
func (nu *Numbered) GetAll() (vals []interface{}) {
nu.mu.Lock()
defer nu.mu.Unlock()
vals = make([]interface{}, 0, len(nu.resources))
for _, nw := range nu.resources {
+ nw.inUse = true
vals = append(vals, nw.val)
}
return vals
}
// GetOutdated returns a list of resources that are older than age, and locks them.
// It does not return any resources that are already locked.
func (nu *Numbered) GetOutdated(age time.Duration, purpose string) (vals []interface{}) {
nu.mu.Lock()
defer nu.mu.Unlock()
now := time.Now()
for _, nw := range nu.resources {
if nw.inUse || !nw.enforceTimeout {
continue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment