Skip to content

Commit b9f41aa

Browse files
committed
doc: update docs.
Signed-off-by: Chen Su <ghosind@gmail.com>
1 parent 5902a9a commit b9f41aa

File tree

8 files changed

+27
-13
lines changed

8 files changed

+27
-13
lines changed

forever.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type ForeverFn func(ctx context.Context, next func(context.Context)) error
1313
// You can use the context and call the next function to pass values to the next invocation. The
1414
// next function can be invoked one time only, and it will have no effect if it is invoked again.
1515
//
16-
// err := Forever(func(ctx context.Context, next func(context.Context)) error {
16+
// err := async.Forever(func(ctx context.Context, next func(context.Context)) error {
1717
// v := ctx.Value("key")
1818
// if v != nil {
1919
// vi := v.(int)

parallel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// limitation if the number is 0.
1313
//
1414
// // Run 2 functions asynchronously at the time.
15-
// out, err := Parallel(2, func(ctx context.Context) (int, error) {
15+
// out, err := async.Parallel(2, func(ctx context.Context) (int, error) {
1616
// // Do something
1717
// return 1, nil
1818
// }, func(ctx context.Context) (string, error) {

race.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
// of the finished function (including panic), and it will not send a cancel signal to other
1010
// functions.
1111
//
12-
// out, index, err := Race(func(ctx context.Context) (int, error) {
12+
// out, index, err := async.Race(func(ctx context.Context) (int, error) {
1313
// request.Get("https://example.com")
1414
// return 0, nil
1515
// }, func(ctx context.Context) (string, error) {

retry.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ type RetryOptions struct {
2929
// the successful task. If all attempts fail, it will return the result and the error of the final
3030
// attempt.
3131
//
32-
// Retry(func() error {
32+
// async.Retry(func() error {
3333
// // Do something
3434
// return err
3535
// }) // Run the function 5 times without interval time or it succeed
3636
//
37-
// Retry(func() error {
37+
// async.Retry(func() error {
3838
// // Do something
3939
// return err
4040
// }, RetryOptions{

seq.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
// function. It returns the result of the last function, or it terminates and returns the error
1010
// that panics or returns by the function in the list.
1111
//
12-
// out, err :=Seq(func () int {
12+
// out, err := async.Seq(func () int {
1313
// return 1
1414
// }, func (n int) int {
1515
// return n + 1
@@ -20,9 +20,10 @@ func Seq(funcs ...AsyncFn) ([]any, error) {
2020
return seq(context.Background(), funcs...)
2121
}
2222

23-
// Seq runs the functions in order with the specified context, and each function consumes the
24-
// returns value of the previous function. It returns the result of the last function, or it
25-
// terminates and returns the error that panics or returns by the function in the list.
23+
// SeqWithContext runs the functions in order with the specified context, and each function
24+
// consumes the returns value of the previous function. It returns the result of the last
25+
// function, or it terminates and returns the error that panics or returns by the function in the
26+
// list.
2627
func SeqWithContext(ctx context.Context, funcs ...AsyncFn) ([]any, error) {
2728
return seq(ctx, funcs...)
2829
}
@@ -75,15 +76,27 @@ func validateSeqFuncs(funcs ...AsyncFn) error {
7576
return nil
7677
}
7778

78-
// SeGroups runs the functions group in order, and it will be terminated if any function returns error.
79+
// SeGroups runs the functions group in order, and it will be terminated if any function returns
80+
// error.
81+
//
82+
// err := async.SeqGroups([]async.AsyncFn{func () {
83+
// // fn 1.a
84+
// }, func () {
85+
// // fn 1.b
86+
// }}, []async.AsyncFn{func() {
87+
// // fn 2
88+
// }})
7989
func SeqGroups(groups ...[]AsyncFn) error {
8090
return seqGroups(context.Background(), groups...)
8191
}
8292

93+
// SeqGroupsWithContext runs the functions group in order with the specified context, and it will
94+
// be terminated if any function returns error.
8395
func SeqGroupsWithContext(ctx context.Context, groups ...[]AsyncFn) error {
8496
return seqGroups(ctx, groups...)
8597
}
8698

99+
// seqGroups runs the functions group in order.
87100
func seqGroups(ctx context.Context, groups ...[]AsyncFn) error {
88101
if len(groups) == 0 {
89102
return nil

series.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
// Each one runs once the previous function has been completed. If any function panics or returns
99
// an error, no more functions are run and it will return immediately.
1010
//
11-
// Series(func () {
11+
// async.Series(func () {
1212
// // do first thing
1313
// }, func () {
1414
// // do second thing
@@ -25,6 +25,7 @@ func SeriesWithContext(ctx context.Context, funcs ...AsyncFn) ([][]any, error) {
2525
return series(ctx, funcs...)
2626
}
2727

28+
// series runs the functions by the order.
2829
func series(ctx context.Context, funcs ...AsyncFn) ([][]any, error) {
2930
validateAsyncFuncs(funcs...)
3031

until.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
// values' types of the execution function.
1616
//
1717
// c := 0
18-
// Until(func() bool {
18+
// async.Until(func() bool {
1919
// return c == 5
2020
// }, func() {
2121
// c++

while.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// - It should have no parameters or accept a context only.
1313
//
1414
// c := 0
15-
// While(func() bool {
15+
// async.While(func() bool {
1616
// return c == 5
1717
// }, func() {
1818
// c++

0 commit comments

Comments
 (0)