Documentation ¶
Overview ¶
Package application offers simple application lifecycle framework.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run runs an instance of Application by the application lifecycle with the given ctx and timeouts. It returns false if the quit timeout occurs. Quit timeout has to be greater than terminate timeout. And it starts after the application context was canceled.
func RunAll ¶ added in v1.1.0
func RunAll(ctx context.Context, apps []Application, terminateTimeout, quitTimeout time.Duration) bool
RunAll runs all instances of Application in common context.Context by the application lifecycle with the given ctx and timeouts. It returns false if the quit timeout occurs. Quit timeout has to be greater than terminate timeout. And it starts after the application context was canceled.
Types ¶
type Application ¶
type Application interface { // Start is always called when the lifecycle starts. // ctx is the application context and can be canceled by the cancel function. Start(ctx context.Context, cancel context.CancelFunc) // Run is called after the Start method if the application context has not been canceled. // ctx is the application context and can be canceled by the cancel function. Run(ctx context.Context, cancel context.CancelFunc) // Terminate is called after the application context was cancelled, with the terminate context which has the given terminate timeout. // If the application context is canceled before the Run method, Terminate is not called. // ctx is the terminate context. Terminate(ctx context.Context) // Stop is always called when the lifecycle ends even the Run method was not called. Stop() }
Application is an interface for handling the application lifecycle. Run and RunAll functions trigger the application lifecycle, and enter methods of the Application interface with the given order.
type Instance ¶ added in v1.4.1
type Instance struct { StartFunc func(ctx context.Context, cancel context.CancelFunc) RunFunc func(ctx context.Context, cancel context.CancelFunc) TerminateFunc func(ctx context.Context) StopFunc func() }
Instance is a method wrapper to implement Application interface.
func (*Instance) Run ¶ added in v1.4.1
func (a *Instance) Run(ctx context.Context, cancel context.CancelFunc)