`waiterr` is a Go package that wraps `sync.WaitGroup` with enhanced error handling capabilities. It allows you to run multiple goroutines, collect any errors they return, and wait for their completion, either returning the first error encountered or aggregating all errors.
## Features
-**`Go(f func() error)`**: Runs a function `f` in a new goroutine, storing any error it returns.
-**`Wait() error`**: Waits for all goroutines to complete and returns a combined error of all non-nil errors.
-**`WaitForError() error`**: Waits for the first error to be returned by any goroutine and immediately returns that error. If all goroutines complete without error, it returns `nil`.
-**`Unwrap() []error`**: Returns a slice of all non-nil errors encountered by the goroutines.
***Differences**: `sync.WaitGroup` is a fundamental primitive for waiting for a collection of goroutines to finish. It does not, however, provide any built-in mechanisms for error propagation or collection. `waiterr` builds upon `sync.WaitGroup` by adding robust error handling, allowing you to collect all errors, or return the first error encountered.
***Differences**: `errgroup.Group` is similar to `waiterr` in that it allows you to run goroutines and collect errors. `errgroup.Group` provides a rate-limiting mechanism, to limit the number of goroutines, which `waiterr` does not provide, as it is intended to be more light-weight. Additionally, `waiterr` provides an `Unwrap` method to retrieve all non-nil errors. Finally `waiterr.WaitErr.Wait` returns a combination of all errors, wheres `errgroup.Group.Wait` only returns the first found error.
***Differences**: `tomb.Tomb` is a more comprehensive library for managing the lifecycle of goroutines, including graceful shutdown, error propagation, and child goroutine management. `waiterr` is a lighter-weight alternative focused specifically on waiting for goroutines and collecting their errors, without the full lifecycle management capabilities of `tomb.Tomb`. If you need advanced goroutine supervision and cleanup, `tomb.Tomb` might be a better fit. For simpler error aggregation and waiting, `waiterr` offers a more streamlined solution.
Please refer to the [CONTRIBUTING.md](CONTRIBUTING.md) file for guidelines on contributing to this project, including code style, commit messages, and Git workflow.