Add inserts an item, and puts it in the queue. The item is only enqueued if it doesn't already exist in the set.
(obj interface{})
| 137 | // Add inserts an item, and puts it in the queue. The item is only enqueued |
| 138 | // if it doesn't already exist in the set. |
| 139 | func (f *FIFO) Add(obj interface{}) error { |
| 140 | id, err := f.keyFunc(obj) |
| 141 | if err != nil { |
| 142 | return KeyError{obj, err} |
| 143 | } |
| 144 | f.lock.Lock() |
| 145 | defer f.lock.Unlock() |
| 146 | f.populated = true |
| 147 | if _, exists := f.items[id]; !exists { |
| 148 | f.queue = append(f.queue, id) |
| 149 | } |
| 150 | f.items[id] = obj |
| 151 | f.cond.Broadcast() |
| 152 | return nil |
| 153 | } |
| 154 | |
| 155 | // AddIfNotPresent inserts an item, and puts it in the queue. If the item is already |
| 156 | // present in the set, it is neither enqueued nor added to the set. |
no outgoing calls