with better closer

This commit is contained in:
2022-09-10 01:39:36 +02:00
parent 6169d05b3e
commit 4214259591
3 changed files with 46 additions and 8 deletions

View File

@@ -23,11 +23,19 @@ type Manager struct {
func NewManager() *Manager {
return &Manager{
logger: &DefaultLogger{}, exitChan: make(chan int, 1),
logger: &DefaultLogger{},
lifetime: ConsoleLifetime,
exitChan: make(chan int, 1),
exitCode: OK,
}
}
func (m *Manager) RunNonBlocking(ctx context.Context) error {
go m.Run(ctx)
return nil
}
func (m *Manager) Run(ctx context.Context) error {
m.initLifetime()
err := m.init(ctx)
@@ -50,9 +58,7 @@ func (m *Manager) Run(ctx context.Context) error {
return err
}
if m.exitCode != 0 {
os.Exit(m.exitCode)
}
os.Exit(m.exitCode)
return nil
}
@@ -97,9 +103,8 @@ func (m *Manager) startComponent(ctx context.Context, component Component) {
err := recover()
if err != nil {
m.logger.Error("Panic occurred in component: %T, error: %s", component, err)
m.exitChan <- Internal
}
m.exitChan <- Internal
}()
m.logger.Info("Starting %T", component)