Skip to content

Commit 67c16d5

Browse files
veqrynolivere
authored andcommitted
Allow RetrierFunc to be an adapter (#827)
1 parent 5c21102 commit 67c16d5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

retrier.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,16 @@ import (
1010
"time"
1111
)
1212

13-
// RetrierFunc specifies the signature of a Retry function.
13+
// RetrierFunc specifies the signature of a Retry function, and is an adapter
14+
// to allow the use of ordinary Retry functions. If f is a function with the
15+
// appropriate signature, RetrierFunc(f) is a Retrier that calls f.
1416
type RetrierFunc func(context.Context, int, *http.Request, *http.Response, error) (time.Duration, bool, error)
1517

18+
// Retry calls f.
19+
func (f RetrierFunc) Retry(ctx context.Context, retry int, req *http.Request, resp *http.Response, err error) (time.Duration, bool, error) {
20+
return f(ctx, retry, req, resp, err)
21+
}
22+
1623
// Retrier decides whether to retry a failed HTTP request with Elasticsearch.
1724
type Retrier interface {
1825
// Retry is called when a request has failed. It decides whether to retry

0 commit comments

Comments
 (0)