Skip to content

Commit

Permalink
fix waitAll (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
haitch committed Nov 17, 2022
1 parent 7cbff30 commit 34c5753
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions wait_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions wait_all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 34c5753

Please sign in to comment.