Role
- Unified reference: One type for local and remote actors. No separate
ActorRef. - Location-transparent: Use
TellandAskthe same way regardless of location. - Identity:
Pathreturns the canonical address.Name,Kindidentify the actor.
Local vs remote
- Local PID: Live mailbox, supervision state, full actor-system reference, etc… Created by
Spawn. - Remote PID: Lightweight handle with address and remoting; messaging via remoting layer. Returned by
ActorOfwhen actor is on another node.
pid.IsLocal() or pid.IsRemote() when location matters. pid.ActorSystem() returns nil for remote PIDs: guard
before use.
Key methods
- Path: Canonical actor identity (host, port, name, system). Returns
Pathinterface. - Name: Actor name within its parent.
- Kind: Reflected type name of the actor. Empty for remote PIDs.
- Tell: Fire-and-forget to another PID.
- Ask: Request-response. Blocks until reply or timeout.
- IsRunning: Actor is active and processing.
- IsSuspended: Actor suspended by supervisor.
- IsStopping: Shutdown in progress.
- Watch: Receive
Terminatedwhencidstops;cidmay live on another node. - UnWatch: Stop watching.
Obtaining a PID
- Spawn:
system.Spawn(ctx, name, actor)returns a local PID. - ActorOf:
system.ActorOf(ctx, name)returns local or remote PID. - Context:
ctx.Self()(current actor),ctx.Sender()(message sender).
NoSender
system.NoSender() returns a special PID for messages without a sender (e.g., scheduled messages, external clients).
Use it when sending from outside the actor system. NoSender().Path() may be used for wire encoding.