| OLD | NEW |
| 1 package looper | 1 package looper |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "expvar" | 4 "expvar" |
| 5 "time" | 5 "time" |
| 6 | 6 |
| 7 "github.com/luci/luci-go/common/clock" | 7 "github.com/luci/luci-go/common/clock" |
| 8 "github.com/luci/luci-go/common/logging" | 8 "github.com/luci/luci-go/common/logging" |
| 9 "golang.org/x/net/context" | 9 "golang.org/x/net/context" |
| 10 ) | 10 ) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 expvars.Add("Errors", 1) | 62 expvars.Add("Errors", 1) |
| 63 if consecErrs++; consecErrs >= maxErrs { | 63 if consecErrs++; consecErrs >= maxErrs { |
| 64 ret.Success = false | 64 ret.Success = false |
| 65 return | 65 return |
| 66 } | 66 } |
| 67 } else { | 67 } else { |
| 68 consecErrs = 0 | 68 consecErrs = 0 |
| 69 } | 69 } |
| 70 | 70 |
| 71 nextCycle = cycle - dur | 71 nextCycle = cycle - dur |
| 72 » » tmr.Reset(nextCycle) | 72 » » if tmr.Reset(nextCycle) { |
| 73 » » » log.Errorf("Timer was still active") |
| 74 » » } |
| 73 } | 75 } |
| 74 | 76 |
| 75 // Run f at least once. | 77 // Run f at least once. |
| 76 run() | 78 run() |
| 77 | 79 |
| 78 // Keep running f until ctx is done. | 80 // Keep running f until ctx is done. |
| 79 for { | 81 for { |
| 80 » » if ar := <-tmr.GetC(); ar.Incomplete() { | 82 » » select { |
| 83 » » case <-ctx.Done(): |
| 84 » » » tmr.Stop() |
| 81 return ret | 85 return ret |
| 82 » » } | 86 » » case <-tmr.GetC(): |
| 83 » » run() | 87 » » » run() |
| 84 » » if !ret.Success { | 88 » » » if !ret.Success { |
| 85 » » » return ret | 89 » » » » return ret |
| 90 » » » } |
| 86 } | 91 } |
| 87 } | 92 } |
| 88 } | 93 } |
| OLD | NEW |