mirror of
https://github.com/niusmallnan/steve.git
synced 2025-09-06 23:50:01 +00:00
Improve counts and columns
This commit is contained in:
29
pkg/clustercache/cancel_collection.go
Normal file
29
pkg/clustercache/cancel_collection.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package clustercache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type cancelCollection struct {
|
||||
id int64
|
||||
items sync.Map
|
||||
}
|
||||
|
||||
func (c *cancelCollection) Add(ctx context.Context, obj interface{}) {
|
||||
key := atomic.AddInt64(&c.id, 1)
|
||||
c.items.Store(key, obj)
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
c.items.Delete(key)
|
||||
}()
|
||||
}
|
||||
|
||||
func (c *cancelCollection) List() (result []interface{}) {
|
||||
c.items.Range(func(key, value interface{}) bool {
|
||||
result = append(result, value)
|
||||
return true
|
||||
})
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user