async
所属分类:collect
开发工具:GO
文件大小:0KB
下载次数:0
上传日期:2020-11-19 17:27:17
上 传 者:
sh-1993
说明: 异步执行函数的安全方法,在发生恐慌时恢复它们。它还提供了一个错误堆栈,旨在促进fa...,
(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.)
文件列表:
.travis.yml (195, 2020-11-19)
LICENCE (1563, 2020-11-19)
Makefile (435, 2020-11-19)
async.go (1884, 2020-11-19)
async_test.go (2945, 2020-11-19)
go.mod (43, 2020-11-19)
runner.go (2109, 2020-11-19)
runner_test.go (2598, 2020-11-19)
## 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)
}
```
近期下载者:
相关文件:
收藏者: