With actual nonblocking one by one manager

This commit is contained in:
Kasper Juul Hermansen 2022-09-21 21:40:44 +02:00
parent 44218ec4ac
commit eb66692b47
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912

View File

@ -30,9 +30,30 @@ func NewManager() *Manager {
} }
} }
func (m *Manager) RunNonBlocking(ctx context.Context) error { type ComponentsAreReady struct {
go m.Run(ctx) }
func (m *Manager) RunNonBlocking(ctx context.Context) error {
m.initLifetime()
err := m.init(ctx)
if err != nil {
return err
}
err = m.startBlocking(ctx)
if err != nil {
return err
}
err = m.wait(ctx)
if err != nil {
return err
}
err = m.shutdown(ctx)
if err != nil {
return err
}
return nil return nil
} }
@ -98,6 +119,14 @@ func (m *Manager) start(ctx context.Context) error {
return nil return nil
} }
func (m *Manager) startBlocking(ctx context.Context) error {
for _, c := range m.components {
m.startComponent(ctx, c)
}
return nil
}
func (m *Manager) startComponent(ctx context.Context, component Component) { func (m *Manager) startComponent(ctx context.Context, component Component) {
defer func() { defer func() {
err := recover() err := recover()