service

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 23, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func New(name string) *Service

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

func (s *Service) ServiceContext() context.Context

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

func (s *Service) ServiceStarted() error

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.

type State added in v0.3.0

type State uint8

State represents the lifecycle states of a service.

const (
	// These are the concrete lifecycle manifestations.
	Idle State = iota
	Started
	Stopping
	Stopped
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL