Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/studiosol/async
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.
https://github.com/studiosol/async
async go hacktoberfest
Last synced: 10 days ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/studiosol/async
- Owner: StudioSol
- License: bsd-3-clause
- Created: 2017-06-30T17:08:33.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-11-19T17:27:17.000Z (almost 4 years ago)
- Last Synced: 2024-08-02T01:25:24.395Z (3 months ago)
- Topics: async, go, hacktoberfest
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 135
- Watchers: 11
- Forks: 18
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-go - async - A safe way to execute functions asynchronously, recovering them in case of panic. (Goroutines / Search and Analytic Databases)
- awesome-go - async - 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. - ★ 11 (Goroutines)
README
## Async
[![Build Status](https://travis-ci.org/StudioSol/async.svg?branch=master)](https://travis-ci.org/StudioSol/async)
[![codecov](https://codecov.io/gh/StudioSol/async/branch/master/graph/badge.svg)](https://codecov.io/gh/StudioSol/async)
[![Go Report Card](https://goreportcard.com/badge/github.com/StudioSol/async)](https://goreportcard.com/report/github.com/StudioSol/async)
[![GoDoc](https://godoc.org/github.com/StudioSol/async?status.svg)](https://godoc.org/github.com/StudioSol/async)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
```go
var (
user User
songs []Songs
photos []Photos
)err := async.Run(ctx,
func(ctx context.Context) error {
user, err = user.Get(ctx, id)
return err
},
func(ctx context.Context) error {
songs, err = song.GetByUserID(ctx, id)
return err
},
func(ctx context.Context) error {
photos, err = photo.GetByUserID(ctx, id)
return err
},
)if err != nil {
log.Error(err)
}
```You can also limit the number of asynchronous tasks
```go
runner := async.NewRunner(tasks...).WithLimit(3)
if err := runner.Run(ctx); err != nil {
log.Error(e)
}
```