Skip to content

Commit b1bddc0

Browse files
committed
Add ErrQueueIsClosed for Channel.TakeWithTimeout()
1 parent e1b1235 commit b1bddc0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

queue.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ func (q ChannelQueue[T]) Take() (T, error) {
154154
// TakeWithTimeout Take the T val(blocking), with timeout
155155
func (q ChannelQueue[T]) TakeWithTimeout(timeout time.Duration) (T, error) {
156156
select {
157-
case val := <-q:
157+
case val, ok := <-q:
158+
if !ok {
159+
return *new(T), ErrQueueIsClosed
160+
}
158161
return val, nil
159162
case <-time.After(timeout):
160163
return *new(T), ErrQueueTakeTimeout

0 commit comments

Comments
 (0)