Skip to content

Commit

Permalink
Hack queue to return the last element when empty
Browse files Browse the repository at this point in the history
  • Loading branch information
gberche-orange committed Oct 29, 2024
1 parent 141b136 commit fd86411
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cmd/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ func (q *Queue[T]) Pop() (*T, bool) {
q.lock.Lock()
defer q.lock.Unlock()

if len(q.slice) == 0 {
return nil, false
}

val := q.slice[0]
q.slice = q.slice[1:]

q.Size--
if len(q.slice) != 0 {
q.slice = q.slice[1:]
q.Size--
}

return &val, true
}

0 comments on commit fd86411

Please sign in to comment.