Skip to content

Repository files navigation

Async

Build StatuscodecovGo Report CardGoDoc

Provides a safe way to execute functions asynchronously, recovering them in case of panic. It also provides an error stack aiming to facilitate fail causes discovery, and a simple way to control execution flow without WaitGroup.

Usage

var (
userUsersongs []Songsphotos []Photos
)
err:=async.Run(ctx,
func(ctx context.Context) error {
user, err=user.Get(ctx, id)
returnerr
},
func(ctx context.Context) error {
songs, err=song.GetByUserID(ctx, id)
returnerr
},
func(ctx context.Context) error {
photos, err=photo.GetByUserID(ctx, id)
returnerr
},
)
iferr!=nil {
log.Error(err)
}

You can also limit the number of asynchronous tasks

runner:=async.NewRunner(tasks...).WithLimit(3)
iferr:=runner.Run(ctx); err!=nil { log.Error(e)
}

About

A safe way to execute functions asynchronously, recovering them in case of panic. It also provides an error stack aiming to facilitate fail causes discovery.

Topics

Resources

Stars

140 stars

Watchers

9 watching

Forks

Releases

Packages

Used by

Contributors

Languages