diff --git a/dsqueue.go b/dsqueue.go index a173a4d..2eb41b8 100644 --- a/dsqueue.go +++ b/dsqueue.go @@ -132,7 +132,8 @@ func (q *DSQueue) GetN(n int) ([][]byte, error) { if n == 0 { return nil, nil } - rsp := make(chan getResponse) + // Buffer response channel so write can happen even if reader gone. + rsp := make(chan getResponse, 1) req := getRequest{ n: n, rsp: rsp, diff --git a/dsqueue_test.go b/dsqueue_test.go index e3dba6f..6963683 100644 --- a/dsqueue_test.go +++ b/dsqueue_test.go @@ -414,7 +414,7 @@ func BenchmarkGetN(b *testing.B) { queue := dsqueue.New(ds, dsqName, dsqueue.WithDedupCacheSize(0)) defer queue.Close() - cids := random.Cids(25) + cids := random.Cids(64) b.ResetTimer() b.ReportAllocs() @@ -423,7 +423,7 @@ func BenchmarkGetN(b *testing.B) { queue.Put(c.Bytes()) } - outItems, err := queue.GetN(50) + outItems, err := queue.GetN(100) if err != nil { b.Fatal(err) }