All
Overview
All runs tasks concurrently and returns when all complete or ctx is cancelled.
If you are coming from Node.js, the closest pattern is Promise.all([a(), b()]).
Signature
go
func All(ctx context.Context, tasks ...func(context.Context) error) errorCompare: Node.js · Standard Go · gox
js
const [a, b] = await Promise.all([fetchA(), fetchB()]);go
errg, ctx := errgroup.WithContext(ctx)
// run goroutines...go
import "github.com/sahilkhaire/gox/async"
a, b, err := async.All(ctx, fetchA, fetchB)Example
go
import "github.com/sahilkhaire/gox/async"
a, b, err := async.All(ctx, fetchA, fetchB)Tips
All async helpers respect context cancellation — prefer them over raw goroutines when you need timeouts.
Standard library alternative
Use the standard library directly:
go
errg, ctx := errgroup.WithContext(ctx)
// run goroutines...