Skip to content

Commit 4db686d

Browse files
committed
feat: Declare the ErrExhausted error.
1 parent 7c7ac99 commit 4db686d

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

budget.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
// Budget calculates the rate of initial calls and the rate of retries over a
1717
// moving one minute window. If the rate of retries exceeds Budget.Rate and the
1818
// ratio of retries exceeds Budget.Ratio, then retries are dropped.
19+
// The Do() function returns ErrExhausted in this case.
1920
//
2021
// Implements the Option interface.
2122
type Budget struct {

retry.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ func Do(ctx context.Context, cb func(context.Context) error, opts ...Option) err
168168
return do(ctx, cb, intOpts)
169169
}
170170

171+
// ErrExhausted is returned by Do() when the retry budget is exhausted.
172+
var ErrExhausted = errors.New("retry budget exhausted")
173+
171174
func do(ctx context.Context, cb func(context.Context) error, opts internalOptions) error {
172175
ch := make(chan error)
173176

@@ -176,7 +179,7 @@ func do(ctx context.Context, cb func(context.Context) error, opts internalOption
176179
ctx := withAttempt(ctx, i)
177180

178181
if !opts.budget.sendOK(i != 0) {
179-
return errors.New("retry budget exhausted")
182+
return ErrExhausted
180183
}
181184

182185
go func(ctx context.Context) {

0 commit comments

Comments
 (0)