Skip to content

Commit e793543

Browse files
committed
feat: function SeqGroups skip empty group.
1 parent f2dbe31 commit e793543

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

seq.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ func seqGroups(ctx context.Context, groups ...[]AsyncFn) error {
9191

9292
tasks := make([]AsyncFn, 0, len(groups))
9393
for _, group := range groups {
94+
if len(group) == 0 {
95+
continue
96+
}
97+
9498
validateAsyncFuncs(group...)
99+
95100
task := func(funcs ...AsyncFn) AsyncFn {
96101
return func(ctx context.Context) error {
97102
_, err := all(ctx, funcs...)

seq_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,32 @@ func TestSeqGroups(t *testing.T) {
125125
}
126126
}
127127

128+
func TestSeqGroupsWithEmptyGroup(t *testing.T) {
129+
a := assert.New(t)
130+
cnts := make([]atomic.Int32, 4)
131+
groups := make([][]async.AsyncFn, 0, 3)
132+
expectedCnts := []int{2, 0, 4, 5}
133+
134+
for i := 0; i < 4; i++ {
135+
tasks := make([]async.AsyncFn, 0)
136+
if i != 1 {
137+
idx := i
138+
for j := 0; j < i+2; j++ {
139+
tasks = append(tasks, func() {
140+
cnts[idx].Add(1)
141+
})
142+
}
143+
}
144+
groups = append(groups, tasks)
145+
}
146+
147+
err := async.SeqGroups(groups...)
148+
a.NilNow(err)
149+
for i := 0; i < 3; i++ {
150+
a.EqualNow(cnts[i].Load(), expectedCnts[i])
151+
}
152+
}
153+
128154
func TestSeqGroupsWithoutTasks(t *testing.T) {
129155
a := assert.New(t)
130156

0 commit comments

Comments
 (0)