Skip to content

Commit 01f5707

Browse files
committed
Add ErrQueueIsClosed for Channel.TakeWithTimeout()
1 parent ad3e1be commit 01f5707

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) Take() (interface{}, error) {
154154
// TakeWithTimeout Take the val(blocking), with timeout
155155
func (q ChannelQueue) TakeWithTimeout(timeout time.Duration) (interface{}, error) {
156156
select {
157-
case val := <-q:
157+
case val, ok := <-q:
158+
if !ok {
159+
return *new(interface{}), ErrQueueIsClosed
160+
}
158161
return val, nil
159162
case <-time.After(timeout):
160163
return *new(interface{}), ErrQueueTakeTimeout

0 commit comments

Comments
 (0)