I'm looking for validation/better design for the below functionality using go channels - Process X in main() has to run after a polling process. After starting process X, it needs to be checked every minute if it is running successfully. On a failure, the process needs to restarted after polling again (if required).
startX := make(chan bool)
startedX := make(chan bool)
startX <- true
for {
select {
case <-startX:
//Check if a worked needs to be started
poll()
// Start process
X.Run()
// Started X
startedX <- true
case <-startedX:
// keep polling for errors
rePoll()
// cancel on error
X.cancel()
// return to startX (To see if the worker needs to be restarted or if another worker has already been started)
startX <- true
}
}
This implementation works! But is there a better way of doing the above? Thanks much!