MCPcopy Create free account
hub / github.com/beeker1121/goque / Pop

Method Pop

stack.go:124–148  ·  view source on GitHub ↗

Pop removes the next item in the stack and returns it.

()

Source from the content-addressed store, hash-verified

122
123// Pop removes the next item in the stack and returns it.
124func (s *Stack) Pop() (*Item, error) {
125 s.Lock()
126 defer s.Unlock()
127
128 // Check if stack is closed.
129 if !s.isOpen {
130 return nil, ErrDBClosed
131 }
132
133 // Try to get the next item in the stack.
134 item, err := s.getItemByID(s.head)
135 if err != nil {
136 return nil, err
137 }
138
139 // Remove this item from the stack.
140 if err := s.db.Delete(item.Key, nil); err != nil {
141 return nil, err
142 }
143
144 // Decrement head position.
145 s.head--
146
147 return item, nil
148}
149
150// Peek returns the next item in the stack without removing it.
151func (s *Stack) Peek() (*Item, error) {

Callers 7

TestStackCloseFunction · 0.80
TestStackPopFunction · 0.80
TestStackEmptyFunction · 0.80
BenchmarkStackPopFunction · 0.80
Example_stackFunction · 0.80

Calls 1

getItemByIDMethod · 0.95

Tested by 7

TestStackCloseFunction · 0.64
TestStackPopFunction · 0.64
TestStackEmptyFunction · 0.64
BenchmarkStackPopFunction · 0.64
Example_stackFunction · 0.64