go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/retry/defaults.go (about) 1 // Copyright 2015 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package retry 16 17 import ( 18 "context" 19 "time" 20 ) 21 22 // defaultIterator defines a template for the default retry parameters that 23 // should be used throughout the program. 24 var defaultIteratorTemplate = ExponentialBackoff{ 25 Limited: Limited{ 26 Delay: 200 * time.Millisecond, 27 Retries: 10, 28 }, 29 MaxDelay: 10 * time.Second, 30 Multiplier: 2, 31 } 32 33 // Default is a Factory that returns a new instance of the default iterator 34 // configuration. 35 func Default() Iterator { 36 it := defaultIteratorTemplate 37 return &it 38 } 39 40 type noneItTemplate struct{} 41 42 func (noneItTemplate) Next(context.Context, error) time.Duration { return Stop } 43 44 // None is a Factory that returns an Iterator that explicitly calls Stop after 45 // the first try. This is helpful to pass to libraries which use retry.Default 46 // if given nil, but where you don't want any retries at all (e.g. tests). 47 func None() Iterator { 48 return noneItTemplate{} 49 }