Documentation
¶
Overview ¶
Package sup provides actors, supervision, runtime events, and typed message inboxes for building concurrent systems.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInboxFull = errors.New("sup: inbox is full")
ErrInboxFull is returned when a non-blocking send cannot be queued.
var ErrSupervisorRunning = errors.New("sup: supervisor is already running")
ErrSupervisorRunning is returned when Run is called while the supervisor is already running.
Functions ¶
This section is empty.
Types ¶
type Actor ¶ added in v0.0.13
type Actor interface {
// ID returns the actor id.
ID() string
// Run starts the actor and blocks until it stops or fails. Context
// cancellation is a clean shutdown and must return nil.
Run(context.Context) error
}
Actor represents a concurrent entity that can be supervised.
Run must return nil when its context is canceled or the actor completes intentionally. It should return a non-nil error only for failures that may require a restart. Panics are recovered by Supervisor and treated as failures.
type ActorFuncOption ¶ added in v0.0.54
type ActorFuncOption func(*actorFunc)
ActorFuncOption configures an actor created by ActorFunc.
func WithSpec ¶ added in v0.0.54
func WithSpec(spec Spec) ActorFuncOption
WithSpec configures an actor function's structured inspection spec.
type CallInbox ¶ added in v0.0.37
CallInbox queues synchronous requests and delivers replies to callers.
func NewCallInbox ¶ added in v0.0.37
NewCallInbox creates a call inbox with the given buffer size.
func (*CallInbox[T, R]) Call ¶ added in v0.0.37
Call sends a request and waits for a reply or context cancellation.
type CallRequest ¶ added in v0.0.8
CallRequest wraps a payload with a reply channel for synchronous calls.
func (CallRequest[T, R]) Context ¶ added in v0.0.54
func (r CallRequest[T, R]) Context() context.Context
Context returns the caller's context.
func (CallRequest[T, R]) Payload ¶ added in v0.0.8
func (r CallRequest[T, R]) Payload() T
Payload returns the request's payload.
func (CallRequest[T, R]) Reply ¶ added in v0.0.8
func (r CallRequest[T, R]) Reply(value R, err error) bool
Reply sends the response back to the caller. It returns false when the caller has canceled, the request is invalid, or a reply was already sent.
type CastInbox ¶ added in v0.0.37
type CastInbox[T any] struct { // contains filtered or unexported fields }
CastInbox queues asynchronous messages for an actor.
func NewCastInbox ¶ added in v0.0.37
NewCastInbox creates a cast inbox with the given buffer size.
func (*CastInbox[T]) Cast ¶ added in v0.0.37
Cast sends a message, blocking until it is queued or the context is canceled.
type Event ¶ added in v0.0.52
type Event struct {
Type EventType
Time time.Time
Actor Actor
Supervisor *Supervisor
Err error
RestartCount int
}
Event describes an actor lifecycle transition emitted by a supervisor.
type EventSink ¶ added in v0.0.54
type EventSink interface {
HandleEvent(Event)
}
EventSink consumes runtime events emitted by a supervisor tree. HandleEvent may be called concurrently by different actors and must return promptly. A panic is recovered so that event handling cannot interrupt supervision.
type EventSinkFunc ¶ added in v0.0.54
type EventSinkFunc func(Event)
EventSinkFunc adapts a function into an EventSink.
func (EventSinkFunc) HandleEvent ¶ added in v0.0.54
func (f EventSinkFunc) HandleEvent(event Event)
HandleEvent calls f with event.
type EventType ¶ added in v0.0.52
type EventType string
EventType identifies the kind of event that occurred.
const ( // EventActorRegistered is emitted when an actor is registered with a supervisor. EventActorRegistered EventType = "actor:registered" // EventActorStarted is emitted when an actor starts running. EventActorStarted EventType = "actor:started" // EventActorStopped is emitted when an actor stops running. EventActorStopped EventType = "actor:stopped" // EventActorRestarting is emitted before a supervisor restarts an actor. EventActorRestarting EventType = "actor:restarting" )
type Inspectable ¶ added in v0.0.43
type Inspectable interface {
Inspect() Spec
}
Inspectable is implemented by actors that expose structured metadata. Inspection is optional and does not affect actor execution or supervision.
type RestartPolicy ¶
type RestartPolicy uint8
RestartPolicy controls when a supervisor restarts a stopped actor.
const ( // Permanent always restarts actors, even after clean exits. Permanent RestartPolicy = iota // Transient restarts actors after errors or panics, but not after clean exits. Transient // Temporary never restarts actors. Temporary )
type Spec ¶ added in v0.0.43
type Spec struct {
Kind string `json:"kind"`
Dependencies []string `json:"dependencies"`
Metadata map[string]any `json:"metadata"`
}
Spec represents a structured description of an inspectable component. It captures the component's kind, its dependency names, and arbitrary configuration metadata for visualization and debugging purposes.
type Supervisor ¶
type Supervisor struct {
// contains filtered or unexported fields
}
Supervisor runs a fixed set of actors and restarts them according to its restart policy. A supervisor is itself an Actor and may be nested.
func NewSupervisor ¶ added in v0.0.7
func NewSupervisor(id string, options ...SupervisorOption) *Supervisor
NewSupervisor creates a supervisor with the given id and options.
func (*Supervisor) ID ¶ added in v0.0.54
func (s *Supervisor) ID() string
ID returns the supervisor id.
func (*Supervisor) Inspect ¶ added in v0.0.43
func (s *Supervisor) Inspect() Spec
Inspect returns the supervisor spec.
func (*Supervisor) Run ¶ added in v0.0.14
func (s *Supervisor) Run(ctx context.Context) error
Run starts all configured actors and blocks until they have all stopped, a restart limit is exceeded, or ctx is canceled. A supervisor may be run again after Run returns. Concurrent calls return ErrSupervisorRunning.
type SupervisorOption ¶ added in v0.0.7
type SupervisorOption func(*Supervisor)
SupervisorOption configures a Supervisor during construction.
func WithActors ¶ added in v0.0.14
func WithActors(actors ...Actor) SupervisorOption
WithActors adds actors that start with the supervisor.
func WithEventSink ¶ added in v0.0.54
func WithEventSink(sinks ...EventSink) SupervisorOption
WithEventSink adds an event sink for runtime events from this supervisor and its descendant supervisors.
func WithPolicy ¶ added in v0.0.7
func WithPolicy(policy RestartPolicy) SupervisorOption
WithPolicy configures the supervisor restart policy.
func WithRestartDelay ¶ added in v0.0.7
func WithRestartDelay(delay time.Duration) SupervisorOption
WithRestartDelay configures the exact delay between actor restart attempts.
func WithRestartLimit ¶ added in v0.0.7
func WithRestartLimit(maxRestarts int, window time.Duration) SupervisorOption
WithRestartLimit limits restarts within a time window.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
dashboard
command
|
|
|
simple
command
|
|
|
Package hub exposes selected sup actors and reactive signals over HTTP.
|
Package hub exposes selected sup actors and reactive signals over HTTP. |
|
mesh
module
|
|
|
modbus
module
|
|
|
Package process adapts standard-library os/exec commands to sup actors.
|
Package process adapts standard-library os/exec commands to sup actors. |
|
Package rx provides shared reactive state and composable channel helpers.
|
Package rx provides shared reactive state and composable channel helpers. |
|
Package sse adapts HTTP server-sent event streams to sup actors.
|
Package sse adapts HTTP server-sent event streams to sup actors. |
|
ws
module
|