Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrServiceAlreadyStarted = errors.New("the service was already started in the past")
ErrServiceAlreadyStarted is returned if there are multiple calls to ServiceStarted. If this happens somethings wrong :/
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents an entity that runs in a separate go routine and where its lifecycle needs to be handled externally.
func New ¶
New instantiates an initialised Service struct. It deliberately does not accept a context as an input parameter as I consider long running service life- cycle handling with contexts as a bad practice. Contexts belong in request/response paths and Services should be handled via channels.
func (*Service) ServiceContext ¶
ServiceContext returns the context associated with this service. This context is passed into requests or similar that are initiated from this service. Doing it this way we can cancel this contexts when someone shuts down the service, which results in all requests being stopped.
func (*Service) ServiceStarted ¶
ServiceStarted marks this service as started.
func (*Service) ServiceStopped ¶
func (s *Service) ServiceStopped()
ServiceStopped marks this service as stopped and ultimately releases an external call to Shutdown.
func (*Service) Shutdown ¶
func (s *Service) Shutdown()
Shutdown instructs the service to gracefully shut down. This function blocks until the done channel was closed which happens when ServiceStopped is called.
func (*Service) SigDone ¶
func (s *Service) SigDone() chan struct{}
SigDone exposes the done channel to listen for service termination.
func (*Service) SigShutdown ¶
func (s *Service) SigShutdown() chan struct{}
SigShutdown exposes the shutdown channel to listen for shutdown instructions.