Git Product home page Git Product logo

syncerr's Introduction

syncerr

Go Report Card Go Reference

Alternative to errgroup.Group that is context-independent and returns all errors.

In some cases it may be desirable to run multiple tasks concurrently and inspect or log the error returned by each of them. This package provides an alternative to errgroup.Group that implements this alternate behavior.

Dependencies

The main module has no dependencies beside the Go standard library.

Usage

The main type provided by this package is Group. Its API is similar to errgroup.Group:

package main

import (
	"errors"
	
	"github.com/nulab/syncerr"
)

func main() {
	// You can initialize a new variable by just using `new`  
	g := new(syncerr.Group)
	
	// run tasks concurrently similarly to what you'd do with errgroup.Group
	g.Go(func() error {
		// do some task
		return errors.New("whoops!")
    })

	g.Go(func() error {
		// do some other task
		return errors.New("ouch!")
	})
	
	// wait for all tasks to complete
	g.Wait()
	
	// this error wraps all errors returned by the child tasks with errors.Join 
	err := g.Error()
	if err != nil {
		// handle error
    }
	// success!
}

Status

This project is actively under development, but it is currently in version 0. Please be aware that the public API and exported methods may undergo changes.

Bug reporting

If you encounter a bug, please open a new issue and include the necessary steps to reproduce it. Thank you!

Authors

License

This project is licensed under the MIT License. For detailed licensing information, refer to the LICENSE file included in the repository.

syncerr's People

Contributors

vibridi avatar

Stargazers

渡邉祐一 / Yuichi Watanabe avatar Yen-Chieh Chen avatar

Watchers

渡邉祐一 / Yuichi Watanabe avatar  avatar  avatar

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.