Documentation
¶
Overview ¶
Package lifecycle runs the process's services as one group: started together and stopped once, in the reverse order they were added, with the log output closed last so the lines written while stopping reach the log files. A service does its own shutdown work in its Stop.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotReady = errors.New("startup work failed")
ErrNotReady is the failure Fail records when it is given none.
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
Group A ServiceGroup is a group of services. Attention: the starting order of the added services is not guaranteed.
func (*Group) Start ¶
func (sg *Group) Start()
Start starts the services together. It blocks until every service's Start returned.
func (*Group) Stop ¶
func (sg *Group) Stop()
Stop stops the services in the reverse order they were added, then closes the log output as the final step. The file output buffers entries, so the lines written while stopping — typically the shutdown errors — only reach the files once the output is closed. The output closes even when a service panics while stopping.
type Readiness ¶ added in v1.21.0
type Readiness struct {
// contains filtered or unexported fields
}
Readiness is a one-shot signal that a piece of startup work is done. The service doing the work calls Ready, or Fail with the reason; the services that depend on it wait on Done and read the outcome from Err. The group starts its services together, so a service that needs another's startup work waits on the signal inside its own Start. The first call decides: later ones change nothing, so a restart re-running the work cannot revoke an outcome the waiters already acted on. A nil Readiness has no waiters.
func NewReadiness ¶ added in v1.21.0
func NewReadiness() *Readiness
NewReadiness returns a signal that has not fired yet.
func (*Readiness) Done ¶ added in v1.21.0
func (r *Readiness) Done() <-chan struct{}
Done is closed once Ready or Fail was called.
func (*Readiness) Err ¶ added in v1.21.0
Err is nil while the work is running and after Ready, and the failure after Fail.
type Service ¶
Service is the interface that groups Start and Stop methods.
func WithStarter ¶
WithStarter wraps a Starter as a Service.