Skip to content

Commit 89f0067

Browse files
author
Mike Atlas
committed
changed ErrUnknown to ErrEmptyQueue (the real error state in the empty queue Peek state)
1 parent 3bd952b commit 89f0067

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

queue/error.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var (
2626
// ErrTimeout is returned when an applicable queue operation times out.
2727
ErrTimeout = errors.New(`queue: poll timed out`)
2828

29-
// ErrUnknown is returned if the error state was unusual and unexpected.
30-
ErrUnknown = errors.New(`queue: unknown error`)
29+
// ErrEmptyQueue is returned when an non-applicable queue operation was called
30+
// due to the queue's empty item state
31+
ErrEmptyQueue = errors.New(`queue: empty queue`)
3132
)

queue/queue.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ func (q *Queue) Peek() (interface{}, error) {
260260
}
261261

262262
peekItem, ok := q.items.peek()
263-
if ok {
264-
return peekItem, nil
263+
if !ok {
264+
return nil, ErrEmptyQueue
265265
}
266266

267-
return nil, ErrUnknown
267+
return peekItem, nil
268268
}
269269

270270
// TakeUntil takes a function and returns a list of items that

0 commit comments

Comments
 (0)