package
0.0.0-20231126024412-02539191b02e
Repository: https://github.com/mjpitz/myago.git
Documentation: pkg.go.dev

# README

lifecycle

Package lifecycle provides common code for hooking into a golang application lifecycle such as setting up a shutdown hook and deferring functions until application shutdown.

import go.pitz.tech/lib/lifecycle

Usage

func Defer

func Defer(fn func(ctx context.Context))

Defer will enqueue a function that will be invoked by Resolve.

func Resolve

func Resolve(ctx context.Context)

Resolve will process all functions that have been enqueued by Defer up until this point.

func Setup

func Setup(ctx context.Context) context.Context

Setup initializes a shutdown hook that cancels the underlying context.

func Shutdown

func Shutdown(ctx context.Context)

Shutdown halts the context, stopping any lingering processes.

type LifeCycle

type LifeCycle struct {
}

LifeCycle hooks into various lifecycle events. It allows functions to be deferred en masse.

func (*LifeCycle) Defer

func (lc *LifeCycle) Defer(fn func(ctx context.Context))

Defer will enqueue a function that will be invoked by Resolve.

func (*LifeCycle) Resolve

func (lc *LifeCycle) Resolve(ctx context.Context)

Resolve will process all functions that have been enqueued by Defer up until this point.

func (*LifeCycle) Setup

func (lc *LifeCycle) Setup(ctx context.Context) context.Context

Setup initializes a shutdown hook that cancels the underlying context.

func (*LifeCycle) Shutdown

func (lc *LifeCycle) Shutdown(ctx context.Context)

# Functions

Defer will enqueue a function that will be invoked by Resolve.
Resolve will process all functions that have been enqueued by Defer up until this point.
Setup initializes a shutdown hook that cancels the underlying context.
Shutdown halts the context, stopping any lingering processes.

# Structs

LifeCycle hooks into various lifecycle events.