Skip to content

Instantly share code, notes, and snippets.

@allenluce
Created July 28, 2015 18:49
Show Gist options
  • Save allenluce/4eff6afc27daf59a4122 to your computer and use it in GitHub Desktop.
Save allenluce/4eff6afc27daf59a4122 to your computer and use it in GitHub Desktop.
var startupErr error
startupTimeoutChan := make(chan bool)
go func() {
for i := 5; i >= 0; i-- {
time.Sleep(time.Second)
startupTimeoutChan <- i == 0
}
}()
StartupLoop:
for ;; {
startupErr = srv.ListenAndServe()
if startupErr.Error() != "listen tcp :80: bind: address already in use" {
break StartupLoop
}
select {
case shouldExit := <- startupTimeoutChan:
if shouldExit {
break StartupLoop
}
if startupErr != nil {
fmt.Printf("%+v, retrying...\n", startupErr)
}
default:
}
}
if startupErr != nil {
fmt.Println("http_start:", startupErr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment