Skip to content
Node: Promise.all, timersgithub.com/sahilkhaire/gox/async

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) error

Compare: Node.js · Standard Go · gox

js
// Typical Promise.all, timers pattern in Node.js
go
// Loop with backoff or context.WithTimeout
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)
})

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.

Back to async package overview

MIT Licensed · Built for Node.js developers moving to Go