Skip to content

Commit

Permalink
Using time.Ticker instead of time.Timer to fire idle time-out event.
Browse files Browse the repository at this point in the history
  • Loading branch information
hetong07 committed Mar 11, 2021
1 parent 81eeb7d commit 696ef70
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/auto-pause/auto-pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,19 @@ var runtime = "docker"
func main() {
// TODO: #10595 make this configurable
const interval = time.Minute * 1
// interval must > 0 or the ticker will panic
if interval <= 0 {
exit.Message(reason.Usage, "Sorry, the auto-pause interval must be greater than 0, got {{.interval}}", out.V{"interval": interval.String()})
}
idleTimeout := time.NewTicker(interval)
defer idleTimeout.Stop()

// channel for incoming messages
go func() {
for {
// On each iteration new timer is created
select {
// TODO: #10596 make it memory-leak proof
case <-time.After(interval):
case <-idleTimeout.C:
runPause()
case <-unpauseRequests:
fmt.Printf("Got request\n")
Expand Down

0 comments on commit 696ef70

Please sign in to comment.