Skip to content

Commit 48de8aa

Browse files
committed
feat: apply executionContainer and rename function.
1 parent 41dd3b6 commit 48de8aa

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

all.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
)
77

88
func All(funcs ...func(context.Context) error) error {
9-
return allWithContext(context.Background(), funcs...)
9+
return all(context.Background(), funcs...)
1010
}
1111

1212
func AllWithContext(ctx context.Context, funcs ...func(context.Context) error) error {
13-
return allWithContext(ctx, funcs...)
13+
return all(ctx, funcs...)
1414
}
1515

16-
func allWithContext(parent context.Context, funcs ...func(context.Context) error) error {
16+
func all(parent context.Context, funcs ...func(context.Context) error) error {
1717
if len(funcs) == 0 {
1818
return nil
1919
}
@@ -32,7 +32,10 @@ func allWithContext(parent context.Context, funcs ...func(context.Context) error
3232
childCtx, childCanFunc := context.WithCancel(ctx)
3333
defer childCanFunc()
3434

35-
err := fn(childCtx)
35+
err := executionContainer(func() error {
36+
return fn(childCtx)
37+
})
38+
3639
select {
3740
case <-ctx.Done():
3841
return

all_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package async_test
1+
package async
22

33
import (
44
"context"
@@ -7,13 +7,12 @@ import (
77
"time"
88

99
"github.com/ghosind/go-assert"
10-
"github.com/ghosind/go-async"
1110
)
1211

1312
func TestAllWithoutFuncs(t *testing.T) {
1413
a := assert.New(t)
1514

16-
err := async.All()
15+
err := All()
1716
a.NilNow(err)
1817
}
1918

@@ -31,7 +30,7 @@ func TestAllSuccess(t *testing.T) {
3130
})
3231
}
3332

34-
err := async.All(funcs...)
33+
err := All(funcs...)
3534
a.NilNow(err)
3635
a.EqualNow(data, []bool{true, true, true, true, true})
3736
}
@@ -53,7 +52,7 @@ func TestAllFailure(t *testing.T) {
5352
})
5453
}
5554

56-
err := async.All(funcs...)
55+
err := All(funcs...)
5756
a.NotNilNow(err)
5857
a.EqualNow(err.Error(), "n = 2")
5958
a.EqualNow(data, []bool{true, true, false, false, false})
@@ -76,7 +75,7 @@ func TestAllWithTimeoutedContext(t *testing.T) {
7675
ctx, canFunc := context.WithTimeout(context.Background(), 150*time.Millisecond)
7776
defer canFunc()
7877

79-
err := async.AllWithContext(ctx, funcs...)
78+
err := AllWithContext(ctx, funcs...)
8079
a.NotNilNow(err)
8180
a.Equal(err.Error(), "context canceled")
8281
a.EqualNow(data, []bool{true, true, false, false, false})

0 commit comments

Comments
 (0)