Documentation
¶
Index ¶
- Variables
- func Call[T any, R any](mb *Mailbox, payload T) (R, error)
- func CallContext[T any, R any](ctx context.Context, mb *Mailbox, payload T) (R, error)
- func Cast[T any](mb *Mailbox, payload T) error
- func CastContext[T any](ctx context.Context, mb *Mailbox, payload T) error
- func TryCall[T any, R any](mb *Mailbox, payload T) (R, error)
- func TryCallContext[T any, R any](ctx context.Context, mb *Mailbox, payload T) (R, error)
- func TryCast[T any](mb *Mailbox, payload T) error
- func TryCastContext[T any](ctx context.Context, mb *Mailbox, payload T) error
- type Actor
- type ActorFunc
- type CallRequest
- type CastRequest
- type Mailbox
- type RepliableRequest
- type RestartPolicy
- type Supervisor
- type SupervisorOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrMailboxFull is returned by TryCast when the mailbox buffer is full. ErrMailboxFull = errors.New("mailbox is full") // ErrMailboxClosed is returned when trying to send to a closed mailbox. ErrMailboxClosed = errors.New("mailbox is closed") )
var ( // ErrMaxRestartsExceeded is returned when the maximum number of restarts is exceeded within the restart window. ErrMaxRestartsExceeded = errors.New("max restarts exceeded") )
Functions ¶
func CallContext ¶ added in v0.0.2
CallContext sends a message to an actor and waits for a reply until the context expires.
func Cast ¶ added in v0.0.8
Cast sends an asynchronous typed envelope, waiting until it can be enqueued or the mailbox is closed. It returns ErrMailboxClosed if the mailbox is closed.
func CastContext ¶ added in v0.0.8
CastContext sends an asynchronous typed envelope with context for enqueue cancellation. It returns ErrMailboxClosed if the mailbox is closed, or ctx.Err() if the context expires before the message is enqueued.
func TryCallContext ¶ added in v0.0.6
TryCallContext attempts to enqueue a request without blocking and waits for reply until ctx expires.
func TryCast ¶ added in v0.0.8
TryCast attempts to send an envelope without blocking. It returns ErrMailboxClosed if the mailbox is closed, or ErrMailboxFull immediately if the mailbox buffer is full.
func TryCastContext ¶ added in v0.0.8
TryCastContext attempts to send an envelope without blocking, but returns ctx.Err() if ctx is done. It returns ErrMailboxClosed if the mailbox is closed, or ErrMailboxFull immediately if the mailbox buffer is full.
Types ¶
type CallRequest ¶ added in v0.0.8
CallRequest wraps a payload with a reply channel for synchronous calls.
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)
Reply sends the response back to the caller. The actor should call this exactly once per request.
type CastRequest ¶ added in v0.0.8
type CastRequest[T any] struct { // contains filtered or unexported fields }
CastRequest wraps a payload for asynchronous calls without expecting a reply.
func (CastRequest[T]) Payload ¶ added in v0.0.8
func (r CastRequest[T]) Payload() T
Payload returns the request's payload.
type Mailbox ¶
type Mailbox struct {
// contains filtered or unexported fields
}
Mailbox is a thread-safe message queue for actors.
func NewMailbox ¶
NewMailbox creates a new mailbox with the specified buffer size. A size of 0 means unbuffered.
func (*Mailbox) Close ¶
func (m *Mailbox) Close()
Close safely closes the mailbox. Subsequent sends fail.
type RepliableRequest ¶ added in v0.0.9
RepliableRequest represents a request that can be replied to.
type RestartPolicy ¶
type RestartPolicy uint8
const ( Permanent RestartPolicy = iota // Always restart, even on clean exits Transient // Restart on errors/panics, but not on clean exits (nil) Temporary // Never restart )
type Supervisor ¶
type Supervisor struct {
// contains filtered or unexported fields
}
Supervisor manages the lifecycle of actor Run loops.
func NewSupervisor ¶ added in v0.0.7
func NewSupervisor(opts ...SupervisorOption) *Supervisor
NewSupervisor creates a new Supervisor with the given options. Panics if the provided options are invalid.
func (*Supervisor) Go ¶
func (s *Supervisor) Go(ctx context.Context, actor Actor)
Go starts the actor's run function in a background goroutine and supervises it.
func (*Supervisor) Running ¶ added in v0.0.4
func (s *Supervisor) Running() int
Running returns the number of currently running actors under supervision.
func (*Supervisor) Wait ¶
func (s *Supervisor) Wait()
Wait blocks until all actors managed by this supervisor have stopped.
type SupervisorOption ¶ added in v0.0.7
type SupervisorOption func(*Supervisor)
Option configures a Supervisor.
func WithOnError ¶ added in v0.0.7
func WithOnError(fn func(error)) SupervisorOption
WithOnError sets a callback invoked when an actor returns an error or panics.
func WithOnRestart ¶ added in v0.0.7
func WithOnRestart(fn func()) SupervisorOption
WithOnRestart sets a callback invoked just before an actor is restarted.
func WithPolicy ¶ added in v0.0.7
func WithPolicy(p RestartPolicy) SupervisorOption
WithPolicy sets the restart policy.
func WithRestartDelay ¶ added in v0.0.7
func WithRestartDelay(d time.Duration) SupervisorOption
WithRestartDelay sets the delay between restarts.
func WithRestartLimit ¶ added in v0.0.7
func WithRestartLimit(maxRestarts int, window time.Duration) SupervisorOption
WithRestartLimit sets the maximum number of restarts allowed within a window. Both maxRestarts and window must be positive; otherwise NewSupervisor panics.