Skip to content

Commit bdf2464

Browse files
batching: close batchChan when disposing
1 parent 588e967 commit bdf2464

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

batcher/batcher.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,18 @@ func (b *basicBatcher) Get() ([]interface{}, error) {
9090
b.lock.RUnlock()
9191
return nil, ErrDisposed
9292
}
93+
b.lock.RUnlock()
9394

9495
var timeout <-chan time.Time
9596
if b.maxTime > 0 {
9697
timeout = time.After(b.maxTime)
9798
}
98-
b.lock.RUnlock()
9999

100100
select {
101-
case items := <-b.batchChan:
102-
b.lock.RLock()
103-
if b.disposed {
101+
case items, ok := <-b.batchChan:
102+
if !ok {
104103
return nil, ErrDisposed
105104
}
106-
b.lock.RUnlock()
107105
return items, nil
108106
case <-timeout:
109107
b.lock.Lock()
@@ -125,7 +123,7 @@ func (b *basicBatcher) Dispose() {
125123
b.lock.Lock()
126124
b.disposed = true
127125
b.items = nil
128-
b.batchChan = nil
126+
close(b.batchChan)
129127
b.lock.Unlock()
130128
}
131129

0 commit comments

Comments
 (0)