Documentation
¶
Overview ¶
Package actor provides a generic, reusable actor pattern for serial message processing with independent context lifecycle.
Index ¶
- Variables
- type Actor
- func (a *Actor[Req, Resp]) Abort() bool
- func (a *Actor[Req, Resp]) Context() context.Context
- func (a *Actor[Req, Resp]) Done() <-chan struct{}
- func (a *Actor[Req, Resp]) InboxLen() int
- func (a *Actor[Req, Resp]) IsPersistent() bool
- func (a *Actor[Req, Resp]) IsRunning() bool
- func (a *Actor[Req, Resp]) LastActive() time.Time
- func (a *Actor[Req, Resp]) Send(req Req) <-chan Result[Resp]
- func (a *Actor[Req, Resp]) Source() string
- func (a *Actor[Req, Resp]) Stop()
- func (a *Actor[Req, Resp]) TrySend(req Req) (<-chan Result[Resp], bool)
- type Handler
- type Option
- type Result
Constants ¶
This section is empty.
Variables ¶
var ErrAborted = errors.New("actor aborted")
ErrAborted is returned when the current execution is aborted via Abort().
var ErrStopped = errors.New("actor stopped")
ErrStopped is returned by Send when the actor has been stopped.
Functions ¶
This section is empty.
Types ¶
type Actor ¶
type Actor[Req, Resp any] struct { // contains filtered or unexported fields }
Actor is a generic execution unit with a serial mailbox and independent context lifecycle.
func (*Actor[Req, Resp]) Abort ¶
Abort cancels the currently running request without stopping the actor. Returns true if a running request was cancelled, false if the actor was idle. Safe to call concurrently and multiple times.
func (*Actor[Req, Resp]) Done ¶
func (a *Actor[Req, Resp]) Done() <-chan struct{}
Done returns a channel that is closed when the actor's run loop has exited. Use this to wait for the actor to fully quiesce after Stop().
func (*Actor[Req, Resp]) IsPersistent ¶
IsPersistent reports whether the actor is exempt from idle reaping.
func (*Actor[Req, Resp]) IsRunning ¶
IsRunning reports whether the actor is currently executing a request.
func (*Actor[Req, Resp]) LastActive ¶
LastActive returns the time of the last activity.
func (*Actor[Req, Resp]) Send ¶
Send delivers a request to the actor's mailbox and returns a channel that receives exactly one Result when processing completes.
type Option ¶
type Option func(*config)
Option configures an Actor.
func WithContext ¶
WithContext sets a parent context for the actor. When this context is cancelled, the actor is cascade-terminated (equivalent to Stop).
func WithDrainTimeout ¶
func WithInboxSize ¶
func WithPersistent ¶
func WithPersistent() Option