1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
17 var neverReady = make(chan struct{}) // never closed
19 // This example passes a context with a signal to tell a blocking function that
20 // it should abandon its work after a signal is received.
21 func ExampleNotifyContext() {
22 ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
25 p, err := os.FindProcess(os.Getpid())
30 // On a Unix-like system, pressing Ctrl+C on a keyboard sends a
31 // SIGINT signal to the process of the program in execution.
33 // This example simulates that by sending a SIGINT signal to itself.
34 if err := p.Signal(os.Interrupt); err != nil {
42 fmt.Println(ctx.Err()) // prints "context canceled"
43 stop() // stop receiving signal notifications as soon as possible.