supervisor

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithContext

func WithContext(ctx context.Context) option

WithContext allows setting a custom context for the supervisor, which can be used to control cancellation and timeouts for the supervised tasks.

func WithPolicy

func WithPolicy(policy policy.Policy) option

WithPolicy allows setting a custom policy for the supervisor, which can be used to control the behavior of the supervised tasks.

func WithStackProvider

func WithStackProvider(stack stack.Provider) option

WithStackProvider allows setting a custom stack provider for the supervisor, which can be used to customize how stack traces are captured and formatted when a task panics.

func WithWriter

func WithWriter(writer io.Writer) option

WithWriter allows setting a custom writer for the supervisor, which can be used to redirect logs and output from the supervised tasks.

Types

type Supervisor

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

Supervisor manages the execution of a Task according to a specified Policy. It handles task restarts based on the outcome of the task and the rules defined in the Policy.

func New

func New(name string, opts ...option) *Supervisor

New creates a new Supervisor with the given name and options. The name is used for logging purposes, while the options allow customization of the supervisor's behavior, such as setting a custom context, policy, writer, or stack provider.

func (*Supervisor) Run

func (s *Supervisor) Run(task Task) error

Run executes the provided Task under the supervision of the Supervisor. It will handle task restarts based on the outcome of the task and the rules defined in the Policy. The method will continue to restart the task according to the policy until the context is cancelled or the restart limit is exceeded.

type Task

type Task func() error

Task represents a unit of work that can be supervised. It is defined as a function that returns an error, which indicates the success or failure of the task.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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