lifecycle

package
v1.20.3 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddShutdownListener

func AddShutdownListener(fn func()) (waitForCalled func())

AddShutdownListener adds fn as a shutdown listener. The returned func can be used to wait for fn getting called.

func AddWrapUpListener

func AddWrapUpListener(fn func()) (waitForCalled func())

AddWrapUpListener adds fn as a wrap up listener. The returned func can be used to wait for fn getting called.

func SetTimeToForceQuit

func SetTimeToForceQuit(duration time.Duration)

SetTimeToForceQuit sets the waiting time before force quitting.

func Shutdown

func Shutdown()

Shutdown calls the registered shutdown listeners, only for test purpose.

func WrapUp

func WrapUp()

WrapUp wraps up the process, only for test purpose.

Types

type Group

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

Group A ServiceGroup is a group of services. Attention: the starting order of the added services is not guaranteed.

func NewServiceGroup

func NewServiceGroup() *Group

NewServiceGroup returns a ServiceGroup.

func (*Group) Add

func (sg *Group) Add(service Service)

Add adds service into sg.

func (*Group) Start

func (sg *Group) Start()

Start starts the ServiceGroup. There should not be any logic code after calling this method, because this method is a blocking one. Also, quitting this method will close the logx output.

func (*Group) Stop

func (sg *Group) Stop()

Stop stops the ServiceGroup.

type Service

type Service interface {
	Starter
	Stopper
}

Service is the interface that groups Start and Stop methods.

func WithStart

func WithStart(start func()) Service

WithStart wraps a start func as a Service.

func WithStarter

func WithStarter(start Starter) Service

WithStarter wraps a Starter as a Service.

type Starter

type Starter interface {
	Start()
}

Starter is the interface wraps the Start method.

type Stopper

type Stopper interface {
	Stop()
}

Stopper is the interface wraps the Stop method.

Jump to

Keyboard shortcuts

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