Skip to content

Commit 6e4aabd

Browse files
committed
feat: add execute result to indicate function result and its index.
1 parent 3eb2bd7 commit 6e4aabd

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

race.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ func race(ctx context.Context, funcs ...func(context.Context) error) (int, error
3333
}
3434

3535
finished := atomic.Bool{}
36-
ch := make(chan struct {
37-
Index int
38-
Error error
39-
})
36+
ch := make(chan executeResult)
4037
defer close(ch)
4138

4239
for i := 0; i < len(funcs); i++ {
@@ -48,10 +45,7 @@ func race(ctx context.Context, funcs ...func(context.Context) error) (int, error
4845
return fn(ctx)
4946
})
5047
if finished.CompareAndSwap(false, true) {
51-
ch <- struct {
52-
Index int
53-
Error error
54-
}{
48+
ch <- executeResult{
5549
Index: n,
5650
Error: err,
5751
}

result.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package async
2+
3+
// executeResult indicates the execution result whether the function returns an error or panic, and
4+
// the index of the function in the parameters list.
5+
type executeResult struct {
6+
// Error is the execution result of the function, it will be nil if the function does not return
7+
// an error and does not panic.
8+
Error error
9+
// Index is the index of the function in the parameters list.
10+
Index int
11+
}

0 commit comments

Comments
 (0)