Skip to content

Commit 34c5753

Browse files
authored
fix waitAll (#23)
1 parent 7cbff30 commit 34c5753

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

wait_all.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ type WaitAllOptions struct {
1919
// first error from any tasks passed in will be returned.
2020
func WaitAll(ctx context.Context, options *WaitAllOptions, tasks ...Waitable) error {
2121
tasksCount := len(tasks)
22+
if tasksCount == 0 {
23+
return nil
24+
}
25+
26+
if options == nil {
27+
options = &WaitAllOptions{}
28+
}
2229

2330
errorCh := make(chan error, tasksCount)
2431
// when failFast enabled, we return on first error we see, while other task may still post error in this channel.

wait_all_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,12 @@ func TestWaitAllCanceled(t *testing.T) {
126126
// wait minor time for the go routine to finish.
127127
time.Sleep(1 * time.Millisecond)
128128
}
129+
130+
func TestWaitAllWithNoTasks(t *testing.T) {
131+
t.Parallel()
132+
ctx, cancelFunc := newTestContextWithTimeout(t, 1*time.Millisecond)
133+
defer cancelFunc()
134+
135+
err := asynctask.WaitAll(ctx, nil)
136+
assert.NoError(t, err)
137+
}

0 commit comments

Comments
 (0)