with better closer
This commit is contained in:
17
manager.go
17
manager.go
@@ -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)
|
||||
|
Reference in New Issue
Block a user