Created
March 2, 2015 05:34
-
-
Save diogomonica/a8fec5bbc8ecae8ad343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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