1
0
mirror of https://github.com/golang/go synced 2024-11-24 07:20:02 -07:00

Documentation.

This commit is contained in:
Nuno Cruces 2022-03-17 16:07:53 +00:00
parent 1380c189c6
commit b1421e4bed

View File

@ -11,18 +11,18 @@ import (
)
func main() {
// ensure that this process terminates when the test times out,
// even if the expected signal never arrives
// Ensure that this process terminates when the test times out,
// even if the expected signal never arrives.
go func() {
io.Copy(io.Discard, os.Stdin)
log.Fatal("stdin is closed; terminating")
}()
// register to receive all signals
// Register to receive all signals.
c := make(chan os.Signal, 1)
signal.Notify(c)
// get console window handle
// Get console window handle.
kernel32 := syscall.NewLazyDLL("kernel32.dll")
getConsoleWindow := kernel32.NewProc("GetConsoleWindow")
hwnd, _, err := getConsoleWindow.Call()
@ -30,7 +30,7 @@ func main() {
log.Fatal("no associated console: ", err)
}
// close console window
// Send message to close the console window.
const _WM_CLOSE = 0x0010
user32 := syscall.NewLazyDLL("user32.dll")
postMessage := user32.NewProc("PostMessageW")
@ -40,8 +40,14 @@ func main() {
}
sig := <-c
// pretend to take some time handling the signal
// Allow some time for the handler to complete if it's going to.
//
// (In https://go.dev/issue/41884 the handler returned immediately,
// which caused Windows to terminate the program before the goroutine
// that received the SIGTERM had a chance to actually clean up.)
time.Sleep(time.Second)
// print signal name, "terminated" makes the test succeed
// Print the signal's name: "terminated" makes the test succeed.
fmt.Println(sig)
}