supervisor

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*options)

Option configures supervisor worker behavior.

func WithBackoff

func WithBackoff(d time.Duration) Option

WithBackoff sets the initial backoff between restarts.

func WithMaxBackoff

func WithMaxBackoff(d time.Duration) Option

WithMaxBackoff caps the backoff between restarts.

func WithMaxRestarts

func WithMaxRestarts(max int) Option

WithMaxRestarts limits the number of restarts (0 = unlimited).

func WithRestartPolicy

func WithRestartPolicy(policy RestartPolicy) Option

WithRestartPolicy sets the restart policy.

type RestartPolicy

type RestartPolicy int

RestartPolicy controls when a worker should be restarted.

const (
	RestartNever RestartPolicy = iota
	RestartOnError
	RestartAlways
)

type Supervisor

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

Supervisor manages worker lifecycles with restart policies.

func New

func New(parent context.Context) *Supervisor

New creates a supervisor bound to the parent context.

func (*Supervisor) Context

func (s *Supervisor) Context() context.Context

Context returns the supervisor context.

func (*Supervisor) SetErrorHandler

func (s *Supervisor) SetErrorHandler(handler func(name string, err error))

SetErrorHandler registers a handler for worker errors.

func (*Supervisor) Start

func (s *Supervisor) Start(name string, fn func(context.Context) error, opts ...Option)

Start runs a worker under supervision.

func (*Supervisor) Stop

func (s *Supervisor) Stop()

Stop cancels all workers and waits for them to exit.

Jump to

Keyboard shortcuts

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