@@ -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.
912func 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.
1319func 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).
1725func 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.
7485func 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 {
0 commit comments