startstop

package
v0.0.0-...-21d01d2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAlreadyStopped      = errors.New("already stopped")
	ErrCannotStopUnstarted = errors.New("cannot stop unstarted service")
)

Functions

This section is empty.

Types

type Once

type Once struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Once contains a State integer

func (*Once) Healthy

func (once *Once) Healthy() error

Healthy returns ErrNotStarted if the state is not started. Override this per-service with more specific implementations.

func (*Once) IfNotStopped

func (once *Once) IfNotStopped(f func()) (ok bool)

IfNotStopped runs the func and returns true if in any state other than Stopped

func (*Once) IfStarted

func (once *Once) IfStarted(f func()) (ok bool)

IfStarted runs the func and returns true only if started, otherwise returns false

func (*Once) Ready

func (once *Once) Ready() error

Ready returns ErrNotStarted if the state is not started.

func (*Once) StartOnce

func (once *Once) StartOnce(name string, fn func() error) error

StartOnce sets the state to Started

func (*Once) State

func (once *Once) State() State

State retrieves the current state

func (*Once) StopOnce

func (once *Once) StopOnce(name string, fn func() error) error

StopOnce sets the state to Stopped

type State

type State int32

State holds the state for Once

const (
	Unstarted State = iota
	Started
	Starting
	StartFailed
	Stopping
	Stopped
	StopFailed
)

func (State) String

func (s State) String() string

Jump to

Keyboard shortcuts

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