Change deferred function call order

This commit is contained in:
Søren Rasmussen 2022-03-06 23:13:00 +01:00
parent df6355e91a
commit b876de55f9
2 changed files with 4 additions and 6 deletions

View file

@ -23,10 +23,9 @@ import (
)
func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream, config *controllers.ControllerConfig) {
defer wg.Done()
hub := sentry.CurrentHub().Clone()
defer hub.Flush(10 * time.Second)
defer wg.Done()
temperature.Initialize()
@ -181,16 +180,15 @@ func main() {
wg.Add(1)
go shutdownHTTP(ctxb, wg, srv)
shutdown()
nc.Close()
wg.Wait()
nc.Close()
log.Print("Shutdown complete")
}
func shutdownHTTP(ctx context.Context, wg *sync.WaitGroup, srv *http.Server) {
defer wg.Done()
hub := sentry.CurrentHub().Clone()
defer hub.Flush(10 * time.Second)
defer wg.Done()
ctx2, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

View file

@ -62,8 +62,8 @@ func NewChamberController(name string, config ControllerConfig, chTemp <-chan te
}
func (p *ChamberController) Run(ctx context.Context, wg *sync.WaitGroup) {
defer wg.Done()
defer p.hub.Flush(10 * time.Second)
defer wg.Done()
ticker := time.NewTicker(1 * time.Second)