diff --git a/wait_all.go b/wait_all.go index c2623f3..5554994 100644 --- a/wait_all.go +++ b/wait_all.go @@ -19,6 +19,13 @@ type WaitAllOptions struct { // first error from any tasks passed in will be returned. func WaitAll(ctx context.Context, options *WaitAllOptions, tasks ...Waitable) error { tasksCount := len(tasks) + if tasksCount == 0 { + return nil + } + + if options == nil { + options = &WaitAllOptions{} + } errorCh := make(chan error, tasksCount) // when failFast enabled, we return on first error we see, while other task may still post error in this channel. diff --git a/wait_all_test.go b/wait_all_test.go index 9aa651c..9740e96 100644 --- a/wait_all_test.go +++ b/wait_all_test.go @@ -126,3 +126,12 @@ func TestWaitAllCanceled(t *testing.T) { // wait minor time for the go routine to finish. time.Sleep(1 * time.Millisecond) } + +func TestWaitAllWithNoTasks(t *testing.T) { + t.Parallel() + ctx, cancelFunc := newTestContextWithTimeout(t, 1*time.Millisecond) + defer cancelFunc() + + err := asynctask.WaitAll(ctx, nil) + assert.NoError(t, err) +}