Back to Lo

Core Attemptwithdelay

docs/data/core-attemptwithdelay.md

1.53.0338 B
Original Source

Invokes a function up to N times with a pause between calls until it returns nil. Returns iterations, elapsed, and error.

go
iter, dur, err := lo.AttemptWithDelay(
    3,
    100*time.Millisecond,
    func(i int, d time.Duration) error {
        if i == 1 {
            return nil
        }
        return errors.New("x")
    },
)