lifecycle

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2021 License: Apache-2.0 Imports: 2 Imported by: 20

Documentation

Overview

Package lifecycle provides application models' lifecycle management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lifecycle

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

Lifecycle manages lifecycle for models. Currently a Lifecycle has two phases: Start and Stop. Currently Lifecycle doesn't support soft dependency models and multi-err, so all models in Lifecycle require to be succeed on both phases.

func (*Lifecycle) Add

func (lc *Lifecycle) Add(m Model)

Add adds a model into LifeCycle.

func (*Lifecycle) AddModels

func (lc *Lifecycle) AddModels(m ...Model)

AddModels adds multiple models into LifeCycle.

func (*Lifecycle) OnStart

func (lc *Lifecycle) OnStart(ctx context.Context) error

OnStart runs models OnStart function if models implmented it. All OnStart functions will be run in parallel. context passed into models' OnStart method will be canceled on the first time a model's OnStart function return non-nil error.

func (*Lifecycle) OnStop

func (lc *Lifecycle) OnStop(ctx context.Context) error

OnStop runs models Start function if models implmented it. All OnStop functions will be run in parallel. context passed into models' OnStop method will be canceled on the first time a model's OnStop function return non-nil error.

type Model

type Model interface{}

Model is application model which may require to start and stop in application lifecycle.

type StartStopper

type StartStopper interface {
	Starter
	Stopper
}

StartStopper is the interface that groups Start and Stop.

type Starter

type Starter interface {
	// Start runs on lifecycle start phase.
	Start(context.Context) error
}

Starter is Model has a Start method.

type Stopper

type Stopper interface {
	// Stop runs on lifecycle stop phase.
	Stop(context.Context) error
}

Stopper is Model has a Stop method.

Jump to

Keyboard shortcuts

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