Documentation ¶
Index ¶
- Constants
- type Service
- type ServiceLifecycle
- func (s *ServiceLifecycle) Done() <-chan struct{}
- func (s *ServiceLifecycle) RegisterServices(services ...Service)
- func (s *ServiceLifecycle) Signals(sigs ...os.Signal) *ServiceLifecycle
- func (s *ServiceLifecycle) StartServices(ctx context.Context) *ServiceLifecycle
- func (s *ServiceLifecycle) StopServices(ctx context.Context)
- func (s *ServiceLifecycle) Wait(ctx context.Context)
Constants ¶
View Source
const StopTimeout = 30
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service interface { // Name describe service name Name() string // Start a service, this method should be used in non-block form Start(ctx context.Context) error // Stop a service, this method should be used in non-block form Stop(ctx context.Context) error }
Service provides abstract methods to control the lifecycle of a service
type ServiceLifecycle ¶
type ServiceLifecycle struct {
// contains filtered or unexported fields
}
ServiceLifecycle manages services' lifecycle
func NewServiceLifecycle ¶
func NewServiceLifecycle() *ServiceLifecycle
NewServiceLifecycle returns a singleton instance of ServiceLifecycle
func (*ServiceLifecycle) Done ¶
func (s *ServiceLifecycle) Done() <-chan struct{}
Done check context is done
func (*ServiceLifecycle) RegisterServices ¶
func (s *ServiceLifecycle) RegisterServices(services ...Service)
RegisterServices register services of an application
func (*ServiceLifecycle) Signals ¶
func (s *ServiceLifecycle) Signals(sigs ...os.Signal) *ServiceLifecycle
Signals registers monitor signals
func (*ServiceLifecycle) StartServices ¶
func (s *ServiceLifecycle) StartServices(ctx context.Context) *ServiceLifecycle
StartServices starts running services
func (*ServiceLifecycle) StopServices ¶
func (s *ServiceLifecycle) StopServices(ctx context.Context)
StopServices stop services when context is done or timeout
func (*ServiceLifecycle) Wait ¶
func (s *ServiceLifecycle) Wait(ctx context.Context)
Wait blocks until context is done
Click to show internal directories.
Click to hide internal directories.