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{})
| 229 | // Important: obj must be a Deltas (the output of the Pop() function). Yes, this is |
| 230 | // different from the Add/Update/Delete functions. |
| 231 | func (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. |