| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package retry | 5 package retry |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "time" | 8 "time" |
| 9 | 9 |
| 10 "github.com/luci/luci-go/common/clock" | 10 "github.com/luci/luci-go/common/clock" |
| 11 "golang.org/x/net/context" | 11 "golang.org/x/net/context" |
| 12 ) | 12 ) |
| 13 | 13 |
| 14 // Limited is an Iterator implementation that is limited by a maximum number of | 14 // Limited is an Iterator implementation that is limited by a maximum number of |
| 15 // retries or time. | 15 // retries or time. |
| 16 type Limited struct { | 16 type Limited struct { |
| 17 » Delay time.Duration // The next generated delay. If zero, 1 second wil
l be used. | 17 » Delay time.Duration // The next generated delay. |
| 18 Retries int // The number of remaining retries. | 18 Retries int // The number of remaining retries. |
| 19 | 19 |
| 20 » MaxTotal time.Duration // The maximum total elasped time. If zero, no ma
ximum will be enfored. | 20 » MaxTotal time.Duration // The maximum total elapsed time. If zero, no ma
ximum will be enforced. |
| 21 | 21 |
| 22 startTime time.Time // The time when the generator initially started. | 22 startTime time.Time // The time when the generator initially started. |
| 23 } | 23 } |
| 24 | 24 |
| 25 var _ Iterator = (*Limited)(nil) | 25 var _ Iterator = (*Limited)(nil) |
| 26 | 26 |
| 27 // Next implements the Iterator interface. | 27 // Next implements the Iterator interface. |
| 28 func (i *Limited) Next(ctx context.Context, _ error) time.Duration { | 28 func (i *Limited) Next(ctx context.Context, _ error) time.Duration { |
| 29 if i.Retries == 0 { | 29 if i.Retries == 0 { |
| 30 return Stop | 30 return Stop |
| (...skipping 17 matching lines...) Expand all Loading... |
| 48 remaining := i.MaxTotal - elapsed | 48 remaining := i.MaxTotal - elapsed |
| 49 if remaining <= 0 { | 49 if remaining <= 0 { |
| 50 // No more time! | 50 // No more time! |
| 51 i.Retries = 0 | 51 i.Retries = 0 |
| 52 return Stop | 52 return Stop |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 return i.Delay | 56 return i.Delay |
| 57 } | 57 } |
| OLD | NEW |