with defer

This commit is contained in:
Kasper Juul Hermansen 2022-09-21 22:08:27 +02:00
parent f9109382cb
commit 5f89d83094
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912

View File

@ -35,6 +35,12 @@ type ComponentsAreReady struct {
func (m *Manager) RunNonBlocking(ctx context.Context, readyChan chan ComponentsAreReady) error { func (m *Manager) RunNonBlocking(ctx context.Context, readyChan chan ComponentsAreReady) error {
go func() error { go func() error {
defer func(ctx context.Context) {
err := m.shutdown(ctx)
if err != nil {
panic(err)
}
}(ctx)
m.initLifetime() m.initLifetime()
err := m.init(ctx) err := m.init(ctx)
if err != nil { if err != nil {
@ -53,10 +59,6 @@ func (m *Manager) RunNonBlocking(ctx context.Context, readyChan chan ComponentsA
return err return err
} }
err = m.shutdown(ctx)
if err != nil {
return err
}
return nil return nil
}() }()
return nil return nil