Skip to content

Commit b1421e4

Browse files
committed
Documentation.
1 parent 1380c18 commit b1421e4

File tree

1 file changed

+13
-7
lines changed
  • src/runtime/testdata/testwinsignal

1 file changed

+13
-7
lines changed

src/runtime/testdata/testwinsignal/main.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@ import (
1111
)
1212

1313
func main() {
14-
// ensure that this process terminates when the test times out,
15-
// even if the expected signal never arrives
14+
// Ensure that this process terminates when the test times out,
15+
// even if the expected signal never arrives.
1616
go func() {
1717
io.Copy(io.Discard, os.Stdin)
1818
log.Fatal("stdin is closed; terminating")
1919
}()
2020

21-
// register to receive all signals
21+
// Register to receive all signals.
2222
c := make(chan os.Signal, 1)
2323
signal.Notify(c)
2424

25-
// get console window handle
25+
// Get console window handle.
2626
kernel32 := syscall.NewLazyDLL("kernel32.dll")
2727
getConsoleWindow := kernel32.NewProc("GetConsoleWindow")
2828
hwnd, _, err := getConsoleWindow.Call()
2929
if hwnd == 0 {
3030
log.Fatal("no associated console: ", err)
3131
}
3232

33-
// close console window
33+
// Send message to close the console window.
3434
const _WM_CLOSE = 0x0010
3535
user32 := syscall.NewLazyDLL("user32.dll")
3636
postMessage := user32.NewProc("PostMessageW")
@@ -40,8 +40,14 @@ func main() {
4040
}
4141

4242
sig := <-c
43-
// pretend to take some time handling the signal
43+
44+
// Allow some time for the handler to complete if it's going to.
45+
//
46+
// (In https://go.dev/issue/41884 the handler returned immediately,
47+
// which caused Windows to terminate the program before the goroutine
48+
// that received the SIGTERM had a chance to actually clean up.)
4449
time.Sleep(time.Second)
45-
// print signal name, "terminated" makes the test succeed
50+
51+
// Print the signal's name: "terminated" makes the test succeed.
4652
fmt.Println(sig)
4753
}

0 commit comments

Comments
 (0)