Skip to content

Instantly share code, notes, and snippets.

@jacoelho
Created August 16, 2016 08:56
Show Gist options
  • Save jacoelho/bf92a7184d14c6a5fc187b3d1eb5ee27 to your computer and use it in GitHub Desktop.
Save jacoelho/bf92a7184d14c6a5fc187b3d1eb5ee27 to your computer and use it in GitHub Desktop.
func fetchWeather(location string) string {
time.Sleep(time.Duration(rand.Intn(10)) * time.Second)
return "sunny"
}
func fallbackWeather() string {
return "raining"
}
func main() {
fuse := &Circuit{
TimeOut: 3,
FailThreshold: 5,
RetryThreshold: 5,
}
var localWeather string
for {
fuse.WithCircuit(func() error {
localWeather = fetchWeather("London")
return nil
},
func() {
localWeather = fallbackWeather()
})
fmt.Println(localWeather)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment