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.

Related tags

go async hacktoberfest
Overview

Async

Build Status codecov Go Report Card GoDoc

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 (
    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

runner := async.NewRunner(tasks...).WithLimit(3)
if err := runner.Run(ctx); err != nil { 
    log.Error(e)
}
Issues
  • Include task runner

    Include task runner

    Example of usage:

    runner := NewRunner(tasks...).WithLimit(3)
    err := runner.Run(ctx) 
    

    Closes https://github.com/StudioSol/async/issues/2 Closes https://github.com/StudioSol/async/issues/3

    opened by rodrigo-brito 2
  • runner handle panic

    runner handle panic

    It shoudle add defer safePanic(cerr) in wrapperChannel to handle panic

    // runner.go
    func wrapperChannel(ctx context.Context, task Task) chan error {
    	cerr := make(chan error, 1)
    	go func() {
    		defer safePanic(cerr)
    
    		cerr <- task(ctx)
    		close(cerr)
    	}()
    	return cerr
    }
    
    // runner_test.go
    func TestRunner_Panic(t *testing.T) {
    	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
    	defer cancel()
    
    	runner := NewRunner(func(context.Context) error {
    		panic(errors.New("test panic"))
    		return nil
    	})
    	err := runner.Run(ctx)
    
    	require.Contains(t, err.Error(), "async.Run: panic test panic")
    }
    
    
    opened by zhaoleigege 2
  • Using Golangci-lint  and go mod

    Using Golangci-lint and go mod

    closes #4

    opened by rafaelrubbioli 1
  • Include async limit

    Include async limit

    The async.Run execute all functions in the same time. Maybe a limit parameter can help with limited asynchronous tasks.

    Suggestion of signature:

    runner := async.NewRunner(tasks...).WithLimit(5).OtherOption(foo, bar)
    err := runner.Do(ctx)
    
    enhancement 
    opened by rodrigo-brito 0
  • Include option to wait all erros finish

    Include option to wait all erros finish

    In the current version, if 3 functions is given and one of the fail, the async run will stop and return this error. The feature consists in include a flag to wait all functions finish and return all erros.

    Suggestion of signature:

    runner := async.NewRunner(tasks...).WaitErrors(true)
    err := runner.Do(ctx)
    

    The erros can be merged with the new errors package: https://golang.org/pkg/errors/#New The option %w will stack all errors in a single one.

    enhancement 
    opened by rodrigo-brito 0
  • Improvements in CI

    Improvements in CI

    • Update Go version
    • Include GolangCI Lint https://github.com/golangci/golangci-lint
    enhancement 
    opened by rodrigo-brito 0
  • Update chopStack function to new format

    Update chopStack function to new format

    chopStack function received improvement recently in PalcoMP3 project. This issue consists in update the function for the new format.

    opened by rodrigo-brito 0
  • runner support panic

    runner support panic

    async.Runner support panic

    opened by zhaoleigege 0
  • Moving from go doc to pkg.go.dev

    Moving from go doc to pkg.go.dev

    opened by AchoArnold 0
  • Remove Convey

    Remove Convey

    • refactor runner_test.go
    opened by marco-silveira 1
Releases(v1.0.0)
Owner
Studio Sol Comunicação Digital Ltda
Studio Sol Comunicação Digital Ltda
Minimalistic and High-performance goroutine worker pool written in Go

pond Minimalistic and High-performance goroutine worker pool written in Go Motivation This library is meant to provide a simple way to limit concurren

Alejandro Durante 268 Sep 6, 2021
Reactive Extensions for the Go language.

RxGo Reactive Extensions for the Go Language ReactiveX ReactiveX, or Rx for short, is an API for programming with Observable streams. This is the offi

ReactiveX 3.7k Sep 10, 2021
A simple and useful goroutine concurrent library.

Taskgroup A simple and useful goroutine concurrent library. Installation go get github.com/anthhub/taskgroup

Tangqy 4 May 19, 2021
🚧 Flexible mechanism to make execution flow interruptible.

?? breaker Flexible mechanism to make execution flow interruptible. ?? Idea The breaker carries a cancellation signal to interrupt an action execution

Kamil Samigullin 0 Jul 11, 2021
Routines was a fixed number thread pool to process the user task, and it would respawn a corresponding new thread when panic

Routines Routines was a fixed number thread pool to process the user task, and it would respawn a corresponding new thread when panic. It supports the

hulk 10 Sep 1, 2021
Hunch provides functions like: All, First, Retry, Waterfall etc., that makes asynchronous flow control more intuitive.

Hunch Hunch provides functions like: All, First, Retry, Waterfall etc., that makes asynchronous flow control more intuitive. About Hunch Go have sever

null 56 Jul 18, 2021
Floc: Orchestrate goroutines with ease.

go-floc Floc: Orchestrate goroutines with ease. The goal of the project is to make the process of running goroutines in parallel and synchronizing the

Andrew Bashkatov 208 Sep 10, 2021
goworker is a Go-based background worker that runs 10 to 100,000* times faster than Ruby-based workers.

goworker goworker is a Resque-compatible, Go-based background worker. It allows you to push jobs into a queue using an expressive language like Ruby w

Benjamin Manns 2.6k Sep 14, 2021
Structured Concurrency in Go

nursery: structured concurrency in Go RunConcurrently( // Job 1 func(context.Context, chan error) { time.Sleep(time.Millisecond * 10)

null 34 Aug 30, 2021
A sync.WaitGroup with error handling and concurrency control

go-waitgroup How to use An package that allows you to use the constructs of a sync.WaitGroup to create a pool of goroutines and control the concurrenc

Pieter Claerhout 20 Jun 19, 2021
Provides some convenient API, includes Goid(), AllGoid(), and LocalStorage, which is a goroutine's local storage, just like ThreadLocal in other languages.

routine 中文版 routine encapsulates and provides some easy-to-use, high-performance goroutine context access interfaces, which can help you access corout

null 23 Sep 13, 2021
Queue is a Golang library for spawning and managing a Goroutine pool

Queue is a Golang library for spawning and managing a Goroutine pool, Alloowing you to create multiple worker according to limit CPU number of machine.

Bo-Yi Wu 63 Sep 11, 2021
gpool - a generic context-aware resizable goroutines pool to bound concurrency based on semaphore.

gpool - a generic context-aware resizable goroutines pool to bound concurrency. Installation $ go get github.com/sherifabdlnaby/gpool import "github.c

Sherif Abdel-Naby 81 Aug 20, 2021
A goroutine pool for Go

Tunny is a Golang library for spawning and managing a goroutine pool, allowing you to limit work coming from any number of goroutines with a synchrono

Ashley Jeffs 2.6k Sep 14, 2021
👷 Library for safely running groups of workers concurrently or consecutively that require input and output through channels

Examples Quickstart Multiple Go Workers Passing Fields Getting Started Pull in the dependency go get github.com/catmullet/go-workers Add the import to

Robert Catmull 114 Aug 25, 2021
Run functions in parallel :comet:

Parallel fn Run functions in parallel. Limit the number of goroutines running at the same time. Installation go get -u github.com/rafaeljesus/parallel

Rafael Jesus 31 Aug 3, 2021
golang worker pool , Concurrency limiting goroutine pool

golang worker pool 中文说明 Concurrency limiting goroutine pool. Limits the concurrency of task execution, not the number of tasks queued. Never blocks su

xxj 321 Aug 30, 2021
Waiting group for collecting goroutine information.

在go语言waitGroup和errGroup都是用来控制goroutine的并发的方式,前者只能等待所有goroutine执行完成之后再执行Wait()函数后面的代码并且不

Jarvib Ding 113 Aug 25, 2021
Queue is a Golang library for spawning and managing a Goroutine pool

Queue is a Golang library for spawning and managing a Goroutine pool, Alloowing you to create multiple worker according to limit CPU number of machine.

golang-queue 56 Sep 3, 2021