github.com/blend/go-sdk@v1.20220411.3/retry/delay_provider.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 "context" 12 "time" 13 ) 14 15 // DelayProvider is a provider for retry delays. 16 type DelayProvider func(context.Context, uint) time.Duration 17 18 // ConstantDelay returns a constant delay provider. 19 func ConstantDelay(d time.Duration) DelayProvider { 20 return func(_ context.Context, _ uint) time.Duration { 21 return d 22 } 23 } 24 25 // ExponentialBackoff is a backoff provider that doubles the base delay each attempt. 26 func ExponentialBackoff(d time.Duration) DelayProvider { 27 return func(_ context.Context, attempt uint) time.Duration { 28 return d * (1 << attempt) 29 } 30 }