Giter Site home page Giter Site logo

studiosol / async Goto Github PK

View Code? Open in Web Editor NEW
135.0 135.0 19.0 26 KB

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.

License: BSD 3-Clause "New" or "Revised" License

Go 95.64% Makefile 4.36%
async go hacktoberfest

async's People

Contributors

guilhermehubner avatar rafaelrubbioli avatar rodrigo-brito avatar vitalbh avatar zhaoleigege avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

async's Issues

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")
}

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.

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.