Skip to content

Commit ada0c8a

Browse files
committed
make Depth() return last cached depth after diskQueue closed
instead of 0 (or, before the preceding change, blocking indefinitely)
1 parent 0331982 commit ada0c8a

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

diskqueue.go

Lines changed: 6 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

0 commit comments

Comments
 (0)