veyron/examples/runtime: make sure we use sync.WaitGroup in the prescribed way:
Add and Wait from the same goroutine, alls Adds done before Wait gets called.
Change-Id: I7ce75d0e058a4b8ee1ccb9cccb84b88bc1e7fc18
diff --git a/examples/runtime/complex_server.go b/examples/runtime/complex_server.go
index 4d60a24..c8e5a01 100644
--- a/examples/runtime/complex_server.go
+++ b/examples/runtime/complex_server.go
@@ -43,7 +43,7 @@
// second signal or stop command while critical cleanup code is
// executing.
var blocking sync.WaitGroup
- blocking.Add(1)
+ blockingCh := make(chan struct{})
// This is how to wait for a signal or stop command and initiate the
// clean shutdown steps.
@@ -66,7 +66,7 @@
case <-sigChan:
case <-stopChan:
}
- blocking.Wait()
+ <-blockingCh
os.Exit(1)
}()
@@ -137,7 +137,8 @@
// Simulate two sequential cleanup steps, one blocking and one
// interruptible.
fmt.Println("Sequential blocking cleanup")
- blocking.Done()
+ blocking.Wait()
+ close(blockingCh)
fmt.Println("Sequential interruptible cleanup")