From 4774158f244c665c11a1a7324c2d8a8b15164fd8 Mon Sep 17 00:00:00 2001 From: kjuulh Date: Wed, 21 Sep 2022 22:14:22 +0200 Subject: [PATCH] with stop --- manager.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/manager.go b/manager.go index ceb8665..984653f 100644 --- a/manager.go +++ b/manager.go @@ -4,6 +4,7 @@ import ( "context" "os" "sync" + "time" ) const ( @@ -35,12 +36,13 @@ type ComponentsAreReady struct { func (m *Manager) RunNonBlocking(ctx context.Context, readyChan chan ComponentsAreReady) error { go func() error { - defer func(ctx context.Context) { + defer func() { + ctx, _ := context.WithTimeout(context.Background(), time.Second*5) err := m.shutdown(ctx) if err != nil { panic(err) } - }(ctx) + }() m.initLifetime() err := m.init(ctx) if err != nil { @@ -164,8 +166,13 @@ func (m *Manager) initLifetime() { } func (m *Manager) wait(ctx context.Context) error { - exitCode := <-m.exitChan - m.exitCode = exitCode + select { + case exitCode := <-m.exitChan: + m.exitCode = exitCode + return nil + case <-ctx.Done(): + return nil + } return nil }