svc

package module
v0.0.0-...-9798210 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: MIT Imports: 4 Imported by: 1

README

github.com/jonasi/svc - just some service helpers and things

pkg.go.dev

Documentation

Index

Constants

View Source
const (
	StateEmpty   = "empty"
	StateStarted = "started"
	StateStopped = "stopped"
)

Valid state values

Variables

View Source
var (
	ErrStartInvalid = errors.New("Attempting to start a service that has already been started")
	ErrStopInvalid  = errors.New("Attempting to stop a service that is not running")
	ErrWaitInvalid  = errors.New("Attempting to wait on a service that is not running")
)

errors

Functions

func Start

func Start(ctx context.Context, svcs ...Service) error

Start starts multiple services

func StartAndWait

func StartAndWait(ctx context.Context, svc Service) error

StartAndWait is helper for the initialization Start & Wait pattern

func Stop

func Stop(ctx context.Context, svcs ...Service) error

Stop stops multiple services

func Wait

func Wait(ctx context.Context, svcs ...Service) error

Wait waits on multiple services

Types

type LifecycleFn

type LifecycleFn func(context.Context) error

LifecycleFn is a helper type for describing the start, stop, wait methods

func LifecycleFnNoCtx

func LifecycleFnNoCtx(fn func() error) LifecycleFn

LifecycleFnNoCtx is a helper that turns a func() error into a LifecycleFn

type Service

type Service interface {
	Start(context.Context) error
	Stop(context.Context) error
	Wait(context.Context) error
}

A Service is a long running process that can start, stop and wait.

func Multi

func Multi(svcs ...Service) Service

Multi returns a new Service that provides a unified Service interface for all of the provided services

func WrapBlocking

func WrapBlocking(start LifecycleFn, stop LifecycleFn) Service

WrapBlocking transforms a blocking start func (like http.ListenAndServe) and returns a Service

func WrapStartStop

func WrapStartStop(start LifecycleFn, stop LifecycleFn) Service

WrapStartStop wraps a start function that returns immediately and returns a Service

Jump to

Keyboard shortcuts

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