github.com/blend/go-sdk@v1.20220411.3/retry/option.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package retry 9 10 import ( 11 "time" 12 ) 13 14 // Option mutates retry options. 15 type Option func(*Retrier) 16 17 // OptMaxAttempts sets the max attempts. 18 func OptMaxAttempts(maxAttempts uint) Option { 19 return func(o *Retrier) { o.MaxAttempts = maxAttempts } 20 } 21 22 // OptDelayProvider sets the retry delay provider. 23 func OptDelayProvider(delayProvider DelayProvider) Option { 24 return func(o *Retrier) { o.DelayProvider = delayProvider } 25 } 26 27 // OptConstantDelay sets the retry delay provider. 28 func OptConstantDelay(d time.Duration) Option { 29 return func(o *Retrier) { o.DelayProvider = ConstantDelay(d) } 30 } 31 32 // OptExponentialBackoff sets the retry delay provider. 33 func OptExponentialBackoff(d time.Duration) Option { 34 return func(o *Retrier) { o.DelayProvider = ExponentialBackoff(d) } 35 } 36 37 // OptShouldRetryProvider sets the should retry provider. 38 func OptShouldRetryProvider(provider ShouldRetryProvider) Option { 39 return func(o *Retrier) { o.ShouldRetryProvider = provider } 40 }