зеркало из https://github.com/Azure/go-asynctask.git
fix waitAll (#23)
This commit is contained in:
Родитель
7cbff3077a
Коммит
34c5753c5c
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче