From fd864114ccece97d3ecc12f1970ddbc84b8056d7 Mon Sep 17 00:00:00 2001 From: Guillaume Berche Date: Tue, 29 Oct 2024 14:16:39 +0100 Subject: [PATCH] Hack queue to return the last element when empty --- cmd/queue.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cmd/queue.go b/cmd/queue.go index e7aa078..06cafd1 100644 --- a/cmd/queue.go +++ b/cmd/queue.go @@ -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 }