Answer the question
In order to leave comments, you need to log in
How to make the program not terminate?
Hello
Tell me how to make a program in Golang that will not end?
You need to write a daemon, write waiting for the button to be pressed does not work when you add the program to the autorun
for{} at the end of the main() block somehow it’s not ethical for the
IDE to replace it with select{}
It certainly works, but somehow I don’t like this code, maybe is there something else?
Answer the question
In order to leave comments, you need to log in
You can create a blocking channel at the end. So you decide when the program ends. It will run until it gets an empty struct from end
end := make(chan struct{})
<- end
It is necessary to specify the task.
If you want the program not to terminate, then you can use the os/signal construct with signals .
For example like this:
// exit program on ps kill and Ctrl+C...
exitc := make(chan os.Signal, 1)
signal.Notify(exitc, os.Interrupt, os.Kill, syscall.SIGTERM)
// some code or goroutines
// ...
sig := <- exitc
// some cleanup or signal logging and printing
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question