diff --git a/batcher/batcher.go b/batcher/batcher.go index 6aed64a..544e48f 100644 --- a/batcher/batcher.go +++ b/batcher/batcher.go @@ -111,8 +111,10 @@ func (b *Batcher) Shutdown(wait bool) { b.flush() if wait { - // wait done channel - <-b.done + if b.done != nil { + // wait done channel + <-b.done + } } } diff --git a/batcher/batcher_test.go b/batcher/batcher_test.go index bff13a7..9115b20 100644 --- a/batcher/batcher_test.go +++ b/batcher/batcher_test.go @@ -88,6 +88,11 @@ func TestShutdownSuccess(t *testing.T) { } } +func TestShutdownEmpty(t *testing.T) { + b := New(10*time.Millisecond, returnsSuccess) + b.Shutdown(true) +} + func TestBatcherError(t *testing.T) { b := New(10*time.Millisecond, returnsError)