Add ListKeys() to FIFO & test

This commit is contained in:
Daniel Smith
2015-03-09 14:48:59 -07:00
parent a8184e81bc
commit e8cc126a56
2 changed files with 49 additions and 37 deletions

View File

@@ -24,8 +24,15 @@ import (
// Queue is exactly like a Store, but has a Pop() method too.
type Queue interface {
Store
// Pop blocks until it has something to return.
Pop() interface{}
// AddIfNotPresent adds a value previously
// returned by Pop back into the queue as long
// as nothing else (presumably more recent)
// has since been added.
AddIfNotPresent(interface{}) error
}
// FIFO receives adds and updates from a Reflector, and puts them in a queue for
@@ -125,6 +132,18 @@ func (f *FIFO) List() []interface{} {
return list
}
// ListKeys returns a list of all the keys of the objects currently
// in the FIFO.
func (f *FIFO) ListKeys() []string {
f.lock.RLock()
defer f.lock.RUnlock()
list := make([]string, 0, len(f.items))
for key := range f.items {
list = append(list, key)
}
return list
}
// Get returns the requested item, or sets exists=false.
func (f *FIFO) Get(obj interface{}) (item interface{}, exists bool, err error) {
key, err := f.keyFunc(obj)