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

Method Pop

tools/cache/heap.go:239–257  ·  view source on GitHub ↗

Pop waits until an item is ready. If multiple items are ready, they are returned in the order given by Heap.data.lessFunc.

()

Source from the content-addressed store, hash-verified

237// Pop waits until an item is ready. If multiple items are
238// ready, they are returned in the order given by Heap.data.lessFunc.
239func (h *Heap) Pop() (interface{}, error) {
240 h.lock.Lock()
241 defer h.lock.Unlock()
242 for len(h.data.queue) == 0 {
243 // When the queue is empty, invocation of Pop() is blocked until new item is enqueued.
244 // When Close() is called, the h.closed is set and the condition is broadcast,
245 // which causes this loop to continue and return from the Pop().
246 if h.closed {
247 return nil, fmt.Errorf("heap is closed")
248 }
249 h.cond.Wait()
250 }
251 obj := heap.Pop(h.data)
252 if obj != nil {
253 return obj, nil
254 } else {
255 return nil, fmt.Errorf("object was removed from heap data")
256 }
257}
258
259// List returns a list of all the items.
260func (h *Heap) List() []interface{} {

Callers 7

TestHeapBasicFunction · 0.95
TestHeap_AddFunction · 0.95
TestHeap_BulkAddFunction · 0.95
TestHeapEmptyPopFunction · 0.95
TestHeap_AddIfNotPresentFunction · 0.95
TestHeap_DeleteFunction · 0.95
TestHeap_UpdateFunction · 0.95

Calls 2

ErrorfMethod · 0.65
PopMethod · 0.65

Tested by 7

TestHeapBasicFunction · 0.76
TestHeap_AddFunction · 0.76
TestHeap_BulkAddFunction · 0.76
TestHeapEmptyPopFunction · 0.76
TestHeap_AddIfNotPresentFunction · 0.76
TestHeap_DeleteFunction · 0.76
TestHeap_UpdateFunction · 0.76