From a59a2781409cfa699f0d6b132b4b43da739b926c Mon Sep 17 00:00:00 2001 From: kjuulh Date: Wed, 21 Sep 2022 22:19:54 +0200 Subject: [PATCH] with callback instead --- manager.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/manager.go b/manager.go index 984653f..77956ec 100644 --- a/manager.go +++ b/manager.go @@ -34,15 +34,10 @@ func NewManager() *Manager { type ComponentsAreReady struct { } -func (m *Manager) RunNonBlocking(ctx context.Context, readyChan chan ComponentsAreReady) error { +type CleanupFunc func(ctx context.Context) error + +func (m *Manager) RunNonBlocking(ctx context.Context, readyChan chan ComponentsAreReady) (CleanupFunc, error) { go func() error { - defer func() { - ctx, _ := context.WithTimeout(context.Background(), time.Second*5) - err := m.shutdown(ctx) - if err != nil { - panic(err) - } - }() m.initLifetime() err := m.init(ctx) if err != nil { @@ -63,7 +58,10 @@ func (m *Manager) RunNonBlocking(ctx context.Context, readyChan chan ComponentsA return nil }() - return nil + + return func(ctx context.Context) error { + return m.shutdown(ctx) + }, nil } func (m *Manager) Run(ctx context.Context) error {