Last active
September 21, 2017 12:00
-
-
Save beautyfree/54bbd5e9289408b76e934f7e4b7d805b to your computer and use it in GitHub Desktop.
Repeatable periodical task job with timeout stop
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
func schedule(what func(), timeout time.Duration) { | |
ch := make(chan bool) | |
go func() { | |
what() | |
ch <- true | |
}() | |
select { | |
case <-time.After(timeout): | |
return | |
case <-ch: | |
return | |
} | |
} | |
func main() { | |
for { | |
schedule(taskPoloniex, 30 * time.Second) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment