From 5f89d8309455c4119efcfe6d3162c0a132239822 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Wed, 21 Sep 2022 22:08:27 +0200 Subject: [PATCH] with defer --- manager.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/manager.go b/manager.go index c04d742..ceb8665 100644 --- a/manager.go +++ b/manager.go @@ -35,6 +35,12 @@ type ComponentsAreReady struct { func (m *Manager) RunNonBlocking(ctx context.Context, readyChan chan ComponentsAreReady) error { go func() error { + defer func(ctx context.Context) { + err := m.shutdown(ctx) + if err != nil { + panic(err) + } + }(ctx) m.initLifetime() err := m.init(ctx) if err != nil { @@ -53,10 +59,6 @@ func (m *Manager) RunNonBlocking(ctx context.Context, readyChan chan ComponentsA return err } - err = m.shutdown(ctx) - if err != nil { - return err - } return nil }() return nil