MCPcopy
hub / github.com/kubernetes/client-go / AddIfNotPresent

Method AddIfNotPresent

tools/cache/delta_fifo.go:231–244  ·  view source on GitHub ↗

AddIfNotPresent inserts an item, and puts it in the queue. If the item is already present in the set, it is neither enqueued nor added to the set. This is useful in a single producer/consumer scenario so that the consumer can safely retry items without contending with the producer and potentially e

(obj interface{})

Source from the content-addressed store, hash-verified

229// Important: obj must be a Deltas (the output of the Pop() function). Yes, this is
230// different from the Add/Update/Delete functions.
231func (f *DeltaFIFO) AddIfNotPresent(obj interface{}) error {
232 deltas, ok := obj.(Deltas)
233 if !ok {
234 return fmt.Errorf("object must be of type deltas, but got: %#v", obj)
235 }
236 id, err := f.KeyOf(deltas.Newest().Object)
237 if err != nil {
238 return KeyError{obj, err}
239 }
240 f.lock.Lock()
241 defer f.lock.Unlock()
242 f.addIfNotPresent(id, deltas)
243 return nil
244}
245
246// addIfNotPresent inserts deltas under id if it does not exist, and assumes the caller
247// already holds the fifo lock.

Callers 1

Calls 4

KeyOfMethod · 0.95
addIfNotPresentMethod · 0.95
NewestMethod · 0.80
ErrorfMethod · 0.65

Tested by 1