Skip to content

Commit f4e9c37

Browse files
committed
doc: add function documentations.
1 parent 73bbe4e commit f4e9c37

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

all.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,22 @@ import (
66
"sync"
77
)
88

9+
// All executes the functions asynchronously until all functions have been finished. If some
10+
// function returns an error or panic, it will return the error immediately and send a cancel
11+
// signal to all other functions by context.
912
func All(funcs ...func(context.Context) error) error {
1013
return all(context.Background(), funcs...)
1114
}
1215

16+
// AllWithContext executes the functions asynchronously until all functions have been finished, or
17+
// the context is done (canceled or timeout). If some function returns an error or panic, it will
18+
// return the error immediately and send a cancel signal to all other functions by context.
1319
func AllWithContext(ctx context.Context, funcs ...func(context.Context) error) error {
1420
return all(ctx, funcs...)
1521
}
1622

23+
// all executes the functions asynchronously until all functions have been finished, or the context
24+
// is done (canceled or timeout).
1725
func all(parent context.Context, funcs ...func(context.Context) error) error {
1826
if len(funcs) == 0 {
1927
return nil
@@ -71,15 +79,30 @@ func all(parent context.Context, funcs ...func(context.Context) error) error {
7179
}
7280
}
7381

82+
// AllCompleted executes the functions asynchronously until all functions have been finished. It
83+
// will return an error slice that is ordered by the functions order, and a boolean value to
84+
// indicate whether any functions return an error or panic.
7485
func AllCompleted(funcs ...func(context.Context) error) ([]error, bool) {
7586
return allCompleted(context.Background(), funcs...)
7687
}
7788

78-
func AllCompletedWithContext(ctx context.Context, funcs ...func(context.Context) error) ([]error, bool) {
89+
// AllCompletedWithContext executes the functions asynchronously until all functions have been
90+
// finished, or the context is done (canceled or timeout). It will return an error slice that is
91+
// ordered by the functions order, and a boolean value to indicate whether any functions return an
92+
// error or panic.
93+
func AllCompletedWithContext(
94+
ctx context.Context,
95+
funcs ...func(context.Context) error,
96+
) ([]error, bool) {
7997
return allCompleted(ctx, funcs...)
8098
}
8199

82-
func allCompleted(parent context.Context, funcs ...func(context.Context) error) (errs []error, hasError bool) {
100+
// allCompleted executes the functions asynchronously until all functions have been finished, or
101+
// the context is done (canceled or timeout).
102+
func allCompleted(
103+
parent context.Context,
104+
funcs ...func(context.Context) error,
105+
) (errs []error, hasError bool) {
83106
hasError = false
84107
errs = make([]error, len(funcs))
85108
if len(funcs) == 0 {

race.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ import (
55
"sync/atomic"
66
)
77

8+
// Race executes the functions asynchronously, it will return the result of the first of the
9+
// finished function (including panic), and it will not send a cancel signal to other functions.
810
func Race(funcs ...func(context.Context) error) error {
911
return race(context.Background(), funcs...)
1012
}
1113

14+
// RaceWithContext executes the functions asynchronously, it will return the result of the first of
15+
// the finished function (including panic), and it will not send a cancel signal to other
16+
// functions.
1217
func RaceWithContext(ctx context.Context, funcs ...func(context.Context) error) error {
1318
return race(ctx, funcs...)
1419
}
1520

21+
// race executes the functions asynchronously, it will return the result of the first of the
22+
// finished function (including panic).
1623
func race(ctx context.Context, funcs ...func(context.Context) error) error {
1724
if len(funcs) == 0 {
1825
return nil

0 commit comments

Comments
 (0)