Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
a59a278140
|
|||
4774158f24
|
23
manager.go
23
manager.go
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -33,14 +34,10 @@ func NewManager() *Manager {
|
|||||||
type ComponentsAreReady struct {
|
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 {
|
go func() error {
|
||||||
defer func(ctx context.Context) {
|
|
||||||
err := m.shutdown(ctx)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
}(ctx)
|
|
||||||
m.initLifetime()
|
m.initLifetime()
|
||||||
err := m.init(ctx)
|
err := m.init(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -61,7 +58,10 @@ func (m *Manager) RunNonBlocking(ctx context.Context, readyChan chan ComponentsA
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
return nil
|
|
||||||
|
return func(ctx context.Context) error {
|
||||||
|
return m.shutdown(ctx)
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) Run(ctx context.Context) error {
|
func (m *Manager) Run(ctx context.Context) error {
|
||||||
@@ -164,9 +164,14 @@ func (m *Manager) initLifetime() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) wait(ctx context.Context) error {
|
func (m *Manager) wait(ctx context.Context) error {
|
||||||
exitCode := <-m.exitChan
|
select {
|
||||||
|
case exitCode := <-m.exitChan:
|
||||||
m.exitCode = exitCode
|
m.exitCode = exitCode
|
||||||
return nil
|
return nil
|
||||||
|
case <-ctx.Done():
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Manager) shutdown(ctx context.Context) error {
|
func (m *Manager) shutdown(ctx context.Context) error {
|
||||||
|
Reference in New Issue
Block a user