From f9261e73885de99b1647d68bedadf2b9a99ad11f Mon Sep 17 00:00:00 2001 From: jswierad Date: Thu, 31 May 2018 18:55:17 +0200 Subject: [PATCH] Make this example code to make more sense I'd suggest to implement worker() implementation to actually do something useful rather than hang on waiting for stop signal to read ;) --- examples/cmd/gd-signal-handling/signal-handling.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/cmd/gd-signal-handling/signal-handling.go b/examples/cmd/gd-signal-handling/signal-handling.go index 64c86a9..203f2b5 100644 --- a/examples/cmd/gd-signal-handling/signal-handling.go +++ b/examples/cmd/gd-signal-handling/signal-handling.go @@ -68,10 +68,13 @@ var ( ) func worker() { + LOOP: for { - time.Sleep(time.Second) - if _, ok := <-stop; ok { - break + time.Sleep(time.Second) // this is work to be done by worker. + select { + case <- stop: + break LOOP + default: } } done <- struct{}{}