actorify

package
v1.24.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package actorify lets you transform a parallel operation into a serialized operation via the Actor pattern1.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrActorDied is returned when the actor inbox or reply channel was closed.
	ErrActorDied = errors.New("actorify: the actor inbox or reply channel was closed")
)

Functions

This section is empty.

Types

type Actor

type Actor[Input, Output any] struct {
	// contains filtered or unexported fields
}

Actor is a serializing wrapper that runs a function in a background goroutine. Whenever the Call method is invoked, a message is sent to the actor's inbox and then the callee waits for a response. Depending on how busy the actor is, this may take a moment.

func New

func New[Input, Output any](ctx context.Context, handler Handler[Input, Output]) *Actor[Input, Output]

New constructs a new Actor and starts its background thread. Cancel the context and you cancel the Actor.

func (*Actor[Input, Output]) Call

func (a *Actor[Input, Output]) Call(ctx context.Context, input Input) (Output, error)

Call calls the Actor with a given Input and returns the handler's Output.

This only works with unary functions by design. If you need to have more inputs, define a struct type to use as a container.

type Handler

type Handler[Input, Output any] func(ctx context.Context, input Input) (Output, error)

Handler is a function alias for the underlying logic the Actor should call.

Jump to

Keyboard shortcuts

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