From 66764cc5b3837e19b951ca44df0bd7e2d613d9cd Mon Sep 17 00:00:00 2001 From: Radek Sohlich Date: Tue, 31 Oct 2017 17:59:29 +0100 Subject: [PATCH] os/signal: improve documentation for the Notify function It is easy to miss the documentation information that no arguments in the Notify function means that the Notify will catch all possible signals. So the example was added with explicit comment above the Notify usage. Fixes #22257 Change-Id: Ia6a16dd4a419f7c77d89020ca5db85979b5b474e Reviewed-on: https://go-review.googlesource.com/74730 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/os/signal/example_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/os/signal/example_test.go b/src/os/signal/example_test.go index 5dfbe5f26b..ecefc757b4 100644 --- a/src/os/signal/example_test.go +++ b/src/os/signal/example_test.go @@ -21,3 +21,18 @@ func ExampleNotify() { s := <-c fmt.Println("Got signal:", s) } + +func ExampleNotify_allSignals() { + // Set up channel on which to send signal notifications. + // We must use a buffered channel or risk missing the signal + // if we're not ready to receive when the signal is sent. + c := make(chan os.Signal, 1) + + // Passing no signals to Notify means that + // all signals will be sent to the channel. + signal.Notify(c) + + // Block until any signal is received. + s := <-c + fmt.Println("Got signal:", s) +} -- 2.48.1