Retry
Overview
Retry calls fn until it succeeds or attempts are exhausted.
Part of the async package — Node.js analog: Promise.all, timers.
Signature
go
func Retry(ctx context.Context, cfg RetryConfig, fn func(context.Context) error) errorCompare: Node.js · Standard Go · gox
js
// Typical Promise.all, timers pattern in Node.jsgo
// Loop with backoff or context.WithTimeoutgo
import "github.com/sahilkhaire/gox/async"
err := async.Retry(ctx, async.RetryConfig{MaxAttempts: 3, Delay: time.Second}, func(ctx context.Context) error {
return fetch(ctx)
})Example
go
import "github.com/sahilkhaire/gox/async"
err := async.Retry(ctx, async.RetryConfig{MaxAttempts: 3, Delay: time.Second}, func(ctx context.Context) error {
return fetch(ctx)
})Tips
All async helpers respect context cancellation — prefer them over raw goroutines when you need timeouts.
Standard library alternative
gox wraps the Go standard library or a trusted dependency with Node-familiar naming. You can use the underlying library directly — see the package overview for escape hatches.