From a2a6a509c33df976a4f96d4a8da9979bed7d8e5a Mon Sep 17 00:00:00 2001 From: Alejandro Durante Date: Tue, 29 Oct 2024 08:37:58 -0300 Subject: [PATCH] fix(group): do not panic when submitting 0 tasks --- group.go | 9 --------- group_test.go | 15 +++++++++------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/group.go b/group.go index 1893e35..df72956 100644 --- a/group.go +++ b/group.go @@ -1,7 +1,6 @@ package pond import ( - "errors" "sync/atomic" "github.com/alitto/pond/v2/internal/future" @@ -51,10 +50,6 @@ type abstractTaskGroup[T func() | func() O, E func() error | func() (O, error), } func (g *abstractTaskGroup[T, E, O]) Submit(tasks ...T) *abstractTaskGroup[T, E, O] { - if len(tasks) == 0 { - panic(errors.New("no tasks provided")) - } - for _, task := range tasks { g.submit(task) } @@ -63,10 +58,6 @@ func (g *abstractTaskGroup[T, E, O]) Submit(tasks ...T) *abstractTaskGroup[T, E, } func (g *abstractTaskGroup[T, E, O]) SubmitErr(tasks ...E) *abstractTaskGroup[T, E, O] { - if len(tasks) == 0 { - panic(errors.New("no tasks provided")) - } - for _, task := range tasks { g.submit(task) } diff --git a/group_test.go b/group_test.go index 8083273..362e9ee 100644 --- a/group_test.go +++ b/group_test.go @@ -148,12 +148,15 @@ func TestTaskGroupWithNoTasks(t *testing.T) { group := NewResultPool[int](10). NewGroup() - assert.PanicsWithError(t, "no tasks provided", func() { - group.Submit() - }) - assert.PanicsWithError(t, "no tasks provided", func() { - group.SubmitErr() - }) + results, err := group.Submit().Wait() + + assert.Equal(t, nil, err) + assert.Equal(t, 0, len(results)) + + results, err = group.SubmitErr().Wait() + + assert.Equal(t, nil, err) + assert.Equal(t, 0, len(results)) } func TestTaskGroupCanceledShouldSkipRemainingTasks(t *testing.T) {