Skip to content

Commit 5d0854e

Browse files
authored
Merge pull request #12 from mgurevin/master
fix blocking Depth() call on the closed queue
2 parents bcaf9bf + ada0c8a commit 5d0854e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

diskqueue.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,12 @@ func New(name string, dataPath string, maxBytesPerFile int64,
138138

139139
// Depth returns the depth of the queue
140140
func (d *diskQueue) Depth() int64 {
141-
return <-d.depthChan
141+
depth, ok := <-d.depthChan
142+
if !ok {
143+
// ioLoop exited
144+
depth = d.depth
145+
}
146+
return depth
142147
}
143148

144149
// ReadChan returns the receive-only []byte channel for reading data
@@ -188,6 +193,8 @@ func (d *diskQueue) exit(deleted bool) error {
188193
// ensure that ioLoop has exited
189194
<-d.exitSyncChan
190195

196+
close(d.depthChan)
197+
191198
if d.readFile != nil {
192199
d.readFile.Close()
193200
d.readFile = nil

0 commit comments

Comments
 (0)