Skip to content

Commit

Permalink
doc: update docs.
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Su <[email protected]>
  • Loading branch information
ghosind committed Jul 23, 2024
1 parent 5902a9a commit b9f41aa
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion forever.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type ForeverFn func(ctx context.Context, next func(context.Context)) error
// You can use the context and call the next function to pass values to the next invocation. The
// next function can be invoked one time only, and it will have no effect if it is invoked again.
//
// err := Forever(func(ctx context.Context, next func(context.Context)) error {
// err := async.Forever(func(ctx context.Context, next func(context.Context)) error {
// v := ctx.Value("key")
// if v != nil {
// vi := v.(int)
Expand Down
2 changes: 1 addition & 1 deletion parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// limitation if the number is 0.
//
// // Run 2 functions asynchronously at the time.
// out, err := Parallel(2, func(ctx context.Context) (int, error) {
// out, err := async.Parallel(2, func(ctx context.Context) (int, error) {
// // Do something
// return 1, nil
// }, func(ctx context.Context) (string, error) {
Expand Down
2 changes: 1 addition & 1 deletion race.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// of the finished function (including panic), and it will not send a cancel signal to other
// functions.
//
// out, index, err := Race(func(ctx context.Context) (int, error) {
// out, index, err := async.Race(func(ctx context.Context) (int, error) {
// request.Get("https://example.com")
// return 0, nil
// }, func(ctx context.Context) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ type RetryOptions struct {
// the successful task. If all attempts fail, it will return the result and the error of the final
// attempt.
//
// Retry(func() error {
// async.Retry(func() error {
// // Do something
// return err
// }) // Run the function 5 times without interval time or it succeed
//
// Retry(func() error {
// async.Retry(func() error {
// // Do something
// return err
// }, RetryOptions{
Expand Down
23 changes: 18 additions & 5 deletions seq.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// function. It returns the result of the last function, or it terminates and returns the error
// that panics or returns by the function in the list.
//
// out, err :=Seq(func () int {
// out, err := async.Seq(func () int {
// return 1
// }, func (n int) int {
// return n + 1
Expand All @@ -20,9 +20,10 @@ func Seq(funcs ...AsyncFn) ([]any, error) {
return seq(context.Background(), funcs...)
}

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

// SeGroups runs the functions group in order, and it will be terminated if any function returns error.
// SeGroups runs the functions group in order, and it will be terminated if any function returns
// error.
//
// err := async.SeqGroups([]async.AsyncFn{func () {
// // fn 1.a
// }, func () {
// // fn 1.b
// }}, []async.AsyncFn{func() {
// // fn 2
// }})
func SeqGroups(groups ...[]AsyncFn) error {
return seqGroups(context.Background(), groups...)
}

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

// seqGroups runs the functions group in order.
func seqGroups(ctx context.Context, groups ...[]AsyncFn) error {
if len(groups) == 0 {
return nil
Expand Down
3 changes: 2 additions & 1 deletion series.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
// Each one runs once the previous function has been completed. If any function panics or returns
// an error, no more functions are run and it will return immediately.
//
// Series(func () {
// async.Series(func () {
// // do first thing
// }, func () {
// // do second thing
Expand All @@ -25,6 +25,7 @@ func SeriesWithContext(ctx context.Context, funcs ...AsyncFn) ([][]any, error) {
return series(ctx, funcs...)
}

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

Expand Down
2 changes: 1 addition & 1 deletion until.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// values' types of the execution function.
//
// c := 0
// Until(func() bool {
// async.Until(func() bool {
// return c == 5
// }, func() {
// c++
Expand Down
2 changes: 1 addition & 1 deletion while.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// - It should have no parameters or accept a context only.
//
// c := 0
// While(func() bool {
// async.While(func() bool {
// return c == 5
// }, func() {
// c++
Expand Down

0 comments on commit b9f41aa

Please sign in to comment.