| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | |
| 3 // that can be found in the LICENSE file. | |
| 4 | |
| 5 package retry | |
| 6 | |
| 7 import ( | |
| 8 "time" | |
| 9 | |
| 10 "github.com/luci/luci-go/common/errors" | |
| 11 "golang.org/x/net/context" | |
| 12 ) | |
| 13 | |
| 14 // transientOnlyIterator is an Iterator implementation that only retries errors | |
| 15 // if they are transient. | |
| 16 // | |
| 17 // (See errors.IsTransient). | |
| 18 type transientOnlyIterator struct { | |
| 19 Iterator // The wrapped Iterator. | |
| 20 } | |
| 21 | |
| 22 func (i *transientOnlyIterator) Next(ctx context.Context, err error) time.Durati
on { | |
| 23 if !errors.IsTransient(err) { | |
| 24 return Stop | |
| 25 } | |
| 26 return i.Iterator.Next(ctx, err) | |
| 27 } | |
| 28 | |
| 29 // TransientOnly returns an Iterator that wraps another Iterator. It will fall | |
| 30 // through to the wrapped Iterator if a transient error is encountered; | |
| 31 // otherwise, it will not retry. | |
| 32 // Returns nil if f is nil. | |
| 33 func TransientOnly(f Factory) Factory { | |
| 34 if f == nil { | |
| 35 return nil | |
| 36 } | |
| 37 return wrap(f, func(it Iterator) Iterator { | |
| 38 return &transientOnlyIterator{it} | |
| 39 }) | |
| 40 } | |
| OLD | NEW |