Skip to content

Commit 325e1d4

Browse files
committed
feat: remove executeContainer function and add utils library.
1 parent 106c04f commit 325e1d4

File tree

6 files changed

+18
-72
lines changed

6 files changed

+18
-72
lines changed

all.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"errors"
66
"sync"
7+
8+
"github.com/ghosind/utils"
79
)
810

911
// All executes the functions asynchronously until all functions have been finished. If some
@@ -43,7 +45,7 @@ func all(parent context.Context, funcs ...func(context.Context) error) error {
4345
childCtx, childCanFunc := context.WithCancel(ctx)
4446
defer childCanFunc()
4547

46-
err := executionContainer(func() error {
48+
err := utils.Try(func() error {
4749
return fn(childCtx)
4850
})
4951

@@ -117,7 +119,7 @@ func allCompleted(
117119
defer childCanFunc()
118120
defer wg.Done()
119121

120-
err := executionContainer(func() error {
122+
err := utils.Try(func() error {
121123
return fn(childCtx)
122124
})
123125
if err != nil {

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ module github.com/ghosind/go-async
33
go 1.17
44

55
require github.com/ghosind/go-assert v0.2.1
6+
7+
require (
8+
github.com/ghosind/utils v0.2.0 // indirect
9+
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
10+
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
github.com/ghosind/go-assert v0.2.1 h1:r5PAkdqHQA8V+CDSiuNW0jghHeTLFY+qRpeF4mkwbYE=
22
github.com/ghosind/go-assert v0.2.1/go.mod h1:PDempWEq6fOdEuqpqTuHh3HC0lCFx+ppaMHiPQbGCas=
3+
github.com/ghosind/utils v0.2.0 h1:U7byV6dLxPY55o89DnrHKLVeOzQMIuATNOjnlyK0ko0=
4+
github.com/ghosind/utils v0.2.0/go.mod h1:TKXXia04sFjVu2qdi//Tqoo5Q87IsOeK94J7Vu+bOAk=
5+
golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No=
6+
golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=

race.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package async
33
import (
44
"context"
55
"sync/atomic"
6+
7+
"github.com/ghosind/utils"
68
)
79

810
// Race executes the functions asynchronously, it will return the result of the first of the
@@ -37,7 +39,9 @@ func race(ctx context.Context, funcs ...func(context.Context) error) error {
3739
fn := funcs[i]
3840

3941
go func() {
40-
err := fn(ctx)
42+
err := utils.Try(func() error {
43+
return fn(ctx)
44+
})
4145
if finished.CompareAndSwap(false, true) {
4246
ch <- err
4347
}

util.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

util_test.go

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)