Skip to content

Instantly share code, notes, and snippets.

@diogomonica
Created March 2, 2015 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diogomonica/a8fec5bbc8ecae8ad343 to your computer and use it in GitHub Desktop.
Save diogomonica/a8fec5bbc8ecae8ad343 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
var results = make(chan string)
type HealthCheck func() string
func healthCheck1() string {
return "healthCheck1"
}
func healthCheck2() string {
return "healthCheck2"
}
func healthCheck3() string {
return "healthCheck3"
}
func ExecuteThing(t *time.Ticker, cs chan string, hc HealthCheck) {
for {
<-t.C
cs <- hc()
}
}
func AddHealthCheck(hc HealthCheck, d time.Duration) {
tick := time.NewTicker(d)
go ExecuteThing(tick, results, hc)
}
func main() {
AddHealthCheck(healthCheck1, time.Second)
AddHealthCheck(healthCheck2, time.Second*30)
AddHealthCheck(healthCheck3, time.Second*5)
for {
select {
case result, channel_ok := <-results:
if channel_ok {
fmt.Println("Received on main: " + result)
} else {
fmt.Println("Channel not ok")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment