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.

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)
}
You might also like...
Myretail-target-case-study - Case study assessment for Target.com

myRetail This project contains two solutions to the Target myRetail case study. The prompt is copied over to PROMPT.md for convenience, but the TLDR i

Generic error handling with panic, recover, and defer.

Generic error handling with panic, recover, and defer.

Modular C2 framework aiming to ease post exploitation for red teamers.

test.mp4 testvideo.mp4 Usage: Inside the command server you can reference beacons using either their list id or their unique id. For example if the ou

Wraps the normal error and provides an error that is easy to use with net/http.

Go HTTP Error Wraps the normal error and provides an error that is easy to use with net/http. Install go get -u github.com/cateiru/go-http-error Usage

Go concurrent-safe, goroutine-safe, thread-safe queue
Go concurrent-safe, goroutine-safe, thread-safe queue

goconcurrentqueue - Concurrent safe queues The package goconcurrentqueue offers a public interface Queue with methods for a queue. It comes with multi

This package provides simple graph to execute functions in a group

Introduction This package provides simple graph to execute functions in a group.

db-recovery is a tool for recovering MySQL data.

db-recovery is a tool for recovering MySQL data. It is used in scenarios where the database has no backup or binlog. It can parse data files and redo/undo logs to recover data.

DNS/DoT to DoH proxy with load-balancing, fail-over and SSL certificate management

dns-proxy Configuration Variable Example Description TLS_DOMAIN my.duckdns.org Domain name without wildcards. Used to create wildcard certificate and

Fail2Connect - Ban connections that fail to connect

Fail2Connect - Ban connections that fail to connect Fail2Connect is a program written in Golang. It reads log files like /var/log/openvpn.log or /var/

Supports the safe and convenient execution of asynchronous computations with goroutines and provides facilities for the safe retrieval of the computation results.

Rendezvous The Rendezvous library supports the safe and convenient execution of asynchronous computations with goroutines and provides facilities for

Framework for performing work asynchronously, outside of the request flow
Framework for performing work asynchronously, outside of the request flow

JobRunner JobRunner is framework for performing work asynchronously, outside of the request flow. It comes with cron to schedule and queue job functio

Gorgonia is a library that helps facilitate machine learning in Go.
Gorgonia is a library that helps facilitate machine learning in Go.

Gorgonia is a library that helps facilitate machine learning in Go. Write and evaluate mathematical equations involving multidimensional arrays easily

Gorgonia is a library that helps facilitate machine learning in Go.
Gorgonia is a library that helps facilitate machine learning in Go.

Gorgonia is a library that helps facilitate machine learning in Go. Write and evaluate mathematical equations involving multidimensional arrays easily

Asynchronously control the different roles available in the kubernetes cluster

RBAC audit Introduction This tool allows you to asynchronously control the different roles available in the kubernetes cluster. These audits are enter

OC Wrapper to facilitate switch clusters quickly

Description OCS is a wrapper for openshift cli-client oc logins to facilitate switching between multiple clusters easily. Install CP binary from repo/

A simple CLI tool that identifies duplicate JARS in a directory. It can remove them also if desired.

Mendix Userlib Cleaner This little utility can be used to identify and clean duplicate JARs. It was created mainly for Mendix apps due to lack of form

Subfinder is a subdomain discovery tool that discovers valid subdomains for websites. Designed as a passive framework to be useful for bug bounties and safe for penetration testing.
Subfinder is a subdomain discovery tool that discovers valid subdomains for websites. Designed as a passive framework to be useful for bug bounties and safe for penetration testing.

Fast passive subdomain enumeration tool. Features • Install • Usage • API Setup • License • Join Discord Subfinder is a subdomain discovery tool that

Comments
  • 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
  • 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
  • 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
  • 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
Releases(v1.0.0)
Owner
Studio Sol Comunicação Digital Ltda
Studio Sol Comunicação Digital Ltda
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 94 Dec 8, 2022
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 36 Dec 31, 2022
A lib for monitoring runtime goroutine stack

Overview A lib for monitoring runtime goroutine stack. Such as wait for goroutines to exit, leak detection, etc. Features context.Context first design

Yad Smood 36 Oct 31, 2022
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 34 Sep 26, 2022
Simply way to control goroutines execution order based on dependencies

Goflow Goflow is a simply package to control goroutines execution order based on dependencies. It works similar to async.auto from node.js async packa

Kamil Drazkiewicz 203 Dec 8, 2022
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 91 Dec 30, 2022
Worker - A Golang library that provides worker pools

Worker A Golang library that provides worker pools. Usage See *_test.go files. T

Fatih Cetinkaya 2 Apr 15, 2022
Reduce debugging time while programming Go. Use static and stack-trace analysis to determine which func call causes the error.

Errlog: reduce debugging time while programming Introduction Use errlog to improve error logging and speed up debugging while you create amazing code

Martin Joly 412 Nov 18, 2022
Package iter provides generic, lazy iterators, functions for producing them from primitive types, as well as functions and methods for transforming and consuming them.

iter Package iter provides generic, lazy iterators, functions for producing them from primitive types, as well as functions and methods for transformi

Matthew Toohey 26 Dec 16, 2022
Package gostackparse parses goroutines stack traces as produced by panic() or debug.Stack() at ~300 MiB/s.

gostackparse Package gostackparse parses goroutines stack traces as produced by panic() or debug.Stack() at ~300 MiB/s. Parsing this data can be usefu

Datadog, Inc. 88 Dec 1, 2022