1 . I called goroutine (which launches a third-party program) and I use wg.Wait()to wait for completion
2 . Before wg.Wait(), I want to give the user the opportunity to cancel this third-party program that works (if he wants)
3 . After the third party is executed, the execution of this user input option should disappear (there is no reason why it should stop the process that has already been executed). Currently, this input must be provided before triggering.wg.Wait()
How can i do this? I was thinking about saving the function optiontoStop()in goroutine and then killing it after completion wg.Wait(), but I could not execute it, or is there a way to send a random value to the scanf blocking call before I return from XYZ? or any other workarounds?
More details:
1 .
func XYZ() {
wg.Add(1)
go doSomething(&wg)
}
2 .
func ABC() {
XYZ()
optiontoStop()
wg.Wait()
}
3 .
func optiontoStop() {
var option string
fmt.Println("Type 'quit' if you want to quit the program")
fmt.Scanf("%s",&string)
}
source
share