Documentation ¶
Overview ¶
Package app provides light-weight utilities around app life cycle events.
Index ¶
Constants ¶
const (
DefaultShutdownTimeout = time.Second * 15
)
Variables ¶
var ProviderSet = wire.NewSet(New, wire.Value(([]AppOptFunc)(nil)))
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
At its core, and app is a place to register work to be done during the life-cycle of the app. And, a central place to signal when to begin shutdown. The zero value of an App is invalid; use New to get a new instance of an App.
Once an app is initialized by calling New, it can be in one of three states.
Running - the normal running state. In this state, it is valid to queue more work by calling App.Go and to queue more shutdown jobs by calling App.OnShutdown. An app will transition out of the running state once any of its tasks, queued via App.Go, return a non-nil error, or if its parent context is cancelled.
Stopping - a limited period of time after shutdown has been signaled to allow for clean-up and finalization tasks to run. In this state, it is valid to queue more work by calling App.OnShutdown. It is invalid to call App.Go in this phase.
Terminated - after all clean-up tasks have complete, or the shutdown grace period has elapsed, the app is in its final terminal state. New work can no longer be queued.
func New ¶
func New(parent context.Context, opts ...AppOptFunc) *App
New initializes an new app for use. By default, it will have the DefaultShutdownTimeout, it will use slog.Default to log, and it will be set to keep-alive. These options can be modified by passing the appropriate opts.
func (*App) Go ¶
Go schedules a task (f) to run as apart of this app. The task will be passed a context that, once canceled, indicates that the app is entering is Stopping phase and this task should exit. If it does not, it will be forcibly terminated after the stopping grace period has passed.
func (*App) OnShutdown ¶
OnShutdown queues a task to run once this app begins entering its shutdown phase.
type AppOptFunc ¶
type AppOptFunc func(*App)
AppOptFunc is an option's function that can be used to override default values of an app during initialization by New.
func WithKeepAlive ¶
func WithKeepAlive(keepAlive bool) AppOptFunc
WithKeepAlive sets the app's keep-alive value.
func WithShutdownTimeout ¶
func WithShutdownTimeout(timeout time.Duration) AppOptFunc
WithShutdownTimeout sets the shutdown grace period to timeout.