service/example: update to not deadlock.

This commit is contained in:
Daniel Theophanes
2014-05-28 11:15:24 -07:00
parent 41caac0c1f
commit 2c5b2362ec
+13 -1
View File
@@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"time"
"bitbucket.org/kardianos/service"
)
@@ -73,10 +74,21 @@ func main() {
}
}
var exit = make(chan struct{})
func doWork() {
log.Info("I'm Running!")
select {}
ticker := time.NewTicker(time.Minute)
for {
select {
case <-ticker.C:
log.Info("Still running...")
case <-exit:
return
}
}
}
func stopWork() {
log.Info("I'm Stopping!")
exit <- struct{}{}
}