Go by Example: Signals
Go by Example : Signals
Sometimes we’d like our Go programs to intelligently
handle
Unix signals
.
For example, we might want a server to gracefully
shutdown when it receives a
| |
| |
| |
| |
Go signal notification works by sending
|
|
|
|
We could receive from
|
|
This goroutine executes a blocking receive for signals. When it gets one it’ll print it out and then notify the program that it can finish. |
|
| |
The program will wait here until it gets the
expected signal (as indicated by the goroutine
above sending a value on
|
|
When we run this program it will block waiting for a
signal. By typing
|
|
Next example: Exit .