runners

package module
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: MIT Imports: 6 Imported by: 2

README

go-runners

Provides a means a simple means of managing long-running functions and services

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Closed added in v1.4.0

func Closed() context.Context

Closed returns an always closed context.

func CtxWithCancel added in v1.5.0

func CtxWithCancel() (context.Context, context.CancelFunc)

CtxWithCancel returns a new context.Context impl with cancel.

Types

type CancelCtx added in v1.5.0

type CancelCtx (<-chan struct{})

CancelCtx is the simplest possible cancellable context.

func (CancelCtx) Deadline added in v1.5.0

func (CancelCtx) Deadline() (time.Time, bool)

func (CancelCtx) Done added in v1.5.0

func (ctx CancelCtx) Done() <-chan struct{}

func (CancelCtx) Err added in v1.5.0

func (ctx CancelCtx) Err() error

func (CancelCtx) GoString added in v1.5.0

func (ctx CancelCtx) GoString() string

func (CancelCtx) String added in v1.5.0

func (ctx CancelCtx) String() string

func (CancelCtx) Value added in v1.5.0

func (CancelCtx) Value(key interface{}) interface{}

type Processor added in v1.6.0

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

Processor acts similarly to a sync.Once object, except that it is reusable. After the first call to Process(), any further calls before this first has returned will block until the first call has returned, and return the same error. This ensures that only a single instance of it is ever running at any one time.

func (*Processor) Process added in v1.6.0

func (p *Processor) Process(proc func() error) (err error)

Process will process the given function if first-call, else blocking until the first function has returned, returning the same error result.

type Service

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

Service provides a means of tracking a single long-running Service, provided protected state changes and preventing multiple instances running. Also providing Service state information.

func (*Service) Done

func (svc *Service) Done() <-chan struct{}

Done returns a channel that's closed when Service.Stop() is called. It is the same channel provided to the currently running service function.

func (*Service) GoRun added in v1.3.0

func (svc *Service) GoRun(fn func(context.Context)) (ok bool)

GoRun will run the supplied function until completion in a goroutine, using given context to propagate cancel. Immediately returns boolean indicating success, or that service is already running.

func (*Service) GoRunWait added in v1.7.0

func (svc *Service) GoRunWait(fn func(context.Context)) (ok bool)

GoRunWait is functionally the same as .RunWait(), but blocks until the first instance of RunWait() returns.

func (*Service) Run

func (svc *Service) Run(fn func(context.Context)) (ok bool)

Run will run the supplied function until completion, using given context to propagate cancel. Immediately returns false if the Service is already running, and true after completed run.

func (*Service) RunWait added in v1.6.0

func (svc *Service) RunWait(fn func(context.Context)) (ok bool)

RunWait is functionally the same as .Run(), but blocks until the first instance of .Run() returns.

func (*Service) Running

func (svc *Service) Running() bool

Running returns if Service is running (i.e. NOT fully stopped, but may be *stopping*).

func (*Service) Stop

func (svc *Service) Stop() bool

Stop will attempt to stop the service, cancelling the running function's context. Immediately returns false if not running, and true only after Service is fully stopped.

Jump to

Keyboard shortcuts

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