Skip to content

Commit 1484dbb

Browse files
committed
fixes from PR review
1 parent 17ef84e commit 1484dbb

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

retry/budget/budget.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ func (q *budget) Stop() {
7777

7878
// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
7979
func (q *budget) Acquire(ctx context.Context) error {
80+
if err := ctx.Err(); err != nil {
81+
return xerrors.WithStackTrace(err)
82+
}
8083
select {
84+
case <-q.done:
85+
return xerrors.WithStackTrace(errClosedBudget)
86+
case <-q.quota:
87+
return nil
8188
case <-ctx.Done():
82-
return ctx.Err()
83-
default:
84-
select {
85-
case <-q.quota:
86-
return nil
87-
case <-ctx.Done():
88-
return xerrors.WithStackTrace(ctx.Err())
89-
}
89+
return xerrors.WithStackTrace(ctx.Err())
9090
}
9191
}

retry/budget/errors.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import (
66
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
77
)
88

9-
// ErrNoQuota is a special error for no quota provided by external retry budget
10-
//
11-
// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
12-
var ErrNoQuota = xerrors.Wrap(errors.New("no retry quota"))
9+
var (
10+
// ErrNoQuota is a special error for no quota provided by external retry budget
11+
//
12+
// Experimental: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#experimental
13+
ErrNoQuota = xerrors.Wrap(errors.New("no retry quota"))
14+
15+
errClosedBudget = xerrors.Wrap(errors.New("retry budget closed"))
16+
)

0 commit comments

Comments
 (0)