refactor: add new starting state

This commit is contained in:
Derrick Hammer 2024-02-27 04:07:12 -05:00
parent ddde672b3c
commit e201c899f4
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 10 additions and 0 deletions

View File

@ -22,6 +22,7 @@ type ServicesImpl struct {
http service.HTTPService
storage service.StorageService
started bool
starting bool
}
func (s *ServicesImpl) HTTP() service.HTTPService {
@ -70,6 +71,10 @@ func (s *ServicesImpl) IsStarted() bool {
return s.started
}
func (s *ServicesImpl) IsStarting() bool {
return s.starting
}
func (s *ServicesImpl) Init(ctx context.Context) error {
for _, svc := range s.All() {
err := svc.Init(ctx)
@ -82,6 +87,9 @@ func (s *ServicesImpl) Init(ctx context.Context) error {
}
func (s *ServicesImpl) Start(ctx context.Context) error {
s.starting = true
for _, svc := range s.All() {
err := svc.Start(ctx)
if err != nil {
@ -90,6 +98,7 @@ func (s *ServicesImpl) Start(ctx context.Context) error {
}
s.started = true
s.starting = false
return nil
}

View File

@ -28,6 +28,7 @@ type Services interface {
All() []Service
Init(ctx context.Context) error
IsStarted() bool
IsStarting() bool
Start(ctx context.Context) error
Stop(ctx context.Context) error
}