lifecycle

package
v0.0.0-...-ad7249d Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: AGPL-3.0 Imports: 4 Imported by: 0

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 github.com/mjpitz/myago/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)

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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.

Types

type LifeCycle

type LifeCycle struct {
	// contains filtered or unexported fields
}

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)

Jump to

Keyboard shortcuts

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