actors

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallService

func CallService[S any, R any](bif Runtime, target Pid, action RpcAction[S, R]) R

func PerformOn

func PerformOn[S any](ctx Ingestor, target Pid, action Action[S])

Types

type Action

type Action[S any] interface {
	Perform(bif Runtime, state *S)
}

type Ingestor

type Ingestor interface {
	//Tell sends m to p.  If p is not alive or does not exist then the runtime will panic within this actor.
	Tell(p Pid, m any)
}

Ingestor is capable of dispatching messages to pids

type Logger

type Logger interface {
	Error(format string, args ...any)
	Fatal(format string, args ...any)
	Info(format string, args ...any)
	Warn(format string, args ...any)
}

type MessageActor

type MessageActor interface {
	OnMessage(r Runtime, m any)
}

type MonitorOpt

type MonitorOpt struct {
	Tell    Pid
	Momento any
}

type NamedRef

type NamedRef struct {
	Name string
}

type NormalExit

type NormalExit struct {
	//Who is the actor which exited
	Who Pid
	//ExitValue is the exiting value provided by the actor
	ExitValue any
	//Momento is state details
	Momento any
}

NormalExit indicates an actor exited with a given value

type PanicExit

type PanicExit struct {
	//Who is the actor which panicked
	Who Pid
	//Momento is the monitors momento
	Momento any
}

PanicExit is a signal to indicate a monitored process has failed

func NewPanicExit

func NewPanicExit(who Pid, momento any) PanicExit

type Pid

type Pid struct {
	Node    uint64
	Process uint64
}

func (*Pid) IsNil

func (p *Pid) IsNil() bool

func (Pid) String

func (p Pid) String() string

type Port

type Port interface {
	Pid() Pid
	ReceiveChannel() <-chan any
	Receive() any
	ReceiveTimeout(wait time.Duration) (any, error)
	ReceiveWith(ctx context.Context) (any, error)
	Tell(ctx context.Context, who Pid, what any)
	Log(ctx context.Context) Logger
	Close(ctx context.Context)
}

type RegisterOpt

type RegisterOpt struct {
	Name string
}

type RpcAction

type RpcAction[S any, R any] interface {
	Invoke(bif Runtime, state S) R
}

type RpcCall

type RpcCall[S any, R any] struct {
	// contains filtered or unexported fields
}

func (*RpcCall[S, R]) Perform

func (r *RpcCall[S, R]) Perform(bif Runtime, state S)

type Runtime

type Runtime interface {
	Ingestor
	//Self results in the Pid of the executing actor
	Self() Pid
	//Log provides a structured mechanism for producing output.
	Log() Logger

	//Spawn a new actor delegating to actor for user messages with the given option set
	Spawn(actor MessageActor, opts ...any) Pid
	//SpawnPort creates a new linked port
	//TODO: Is this the correct place?
	SpawnPort() Port

	//SpawnMonitor starts a new actor dispatching to actor, returning Pid.  Scheduling location is up the runtime.
	//Deprecated: use Spawn(actor, MonitoringOpt{tell: who})
	SpawnMonitor(actor MessageActor) Pid
	//diff between mailbox and port: port is intended for external commms, mailbox is meant for rpc like comms
	SpawnMailbox() Port

	//Monitor2 allows external monitoring between two processes
	Monitor2(watching Pid, watcher Pid)
	//Unmonitor will remove the {watched,watcher} pairs.
	Unmonitor(watched Pid, watcher Pid)

	Terminate(target Pid)
	Exit(result any)

	Register(name string, who Pid)
	Unregister(name string)
	LookupPath(path string) Pid
	NamedRef(name string) string
	SelfNamedRef() string

	//Context is the context of the currently invoking tick
	Context() context.Context
}

Runtime represents the world from teh point of view of an actor. Actors must use this interface to work within the actor system.

type Start

type Start struct{}

Start indicates the actor is starting execution and should perform any in actor initialization

type System

type System interface {
	Tell(ctx context.Context, p Pid, m any)
	//NewPort creates a local port on the system
	NewPort() Port
	//Spawn a new actor delegating to actor for user messages with the given option set
	Spawn(ctx context.Context, actor MessageActor, opts ...any) Pid
	Lookup(ctx context.Context, absolutePath string) Pid
}

System is intended to represent an entire node

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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