Nexus API Reference

ActorRef

Type-safe reference to an actor — the only handle user code holds.

ActorRef is the public face of every actor. You obtain a ref from ActorSystem::spawn() or ActorContext::spawn() and use it to send messages without any knowledge of where or how the actor is running (local fiber, Swoole coroutine, remote worker thread, or dead-letter sink).

Concrete implementations include LocalActorRef (in-process), WorkerActorRef (cross-thread in a worker pool), and DeadLetterRef (null object for stopped or non-existent actors). User code should only depend on this interface.

Example:

$ref = $system->spawn(Props::fromBehavior($behavior), 'counter');

// Fire-and-forget
$ref->tell(new Increment());

// Request-response (suspends the current fiber until the reply arrives)
$count = $ref->ask(new GetCount(), Duration::seconds(5))->await();
Tags
see
ActorSystem::spawn()

to obtain an ActorRef

see
ActorContext::spawn()

to spawn child actors

see
Props

for configuring how the actor is spawned

psalm-api
template

T of object

Table of Contents

Methods

ask()  : Future<string|int, R>
Send a message and get a Future for the reply.
isAlive()  : bool
Return true if the actor is still running and able to receive messages.
path()  : ActorPath
Return the hierarchical path that uniquely identifies this actor in the system.
tell()  : void
Send a message to the actor without waiting for a reply (fire-and-forget).

Methods

ask()

Send a message and get a Future for the reply.

public ask(T $message, Duration $timeout) : Future<string|int, R>

The message is sent immediately (eager). The reply is received via a lightweight FutureSlot. The handler replies with ctx->reply().

Parameters
$message : T
$timeout : Duration
Tags
template

R of object

throws
AskTimeoutException
Return values
Future<string|int, R>

isAlive()

Return true if the actor is still running and able to receive messages.

public isAlive() : bool

Returns false once the actor has stopped or its mailbox has been closed. Messages sent to a stopped actor are forwarded to dead letters.

Return values
bool

path()

Return the hierarchical path that uniquely identifies this actor in the system.

public path() : ActorPath

Paths have the form /user/parent/child and are stable for the lifetime of the actor. They appear in log output and are used as routing keys in the worker pool and cluster layers.

Return values
ActorPath

tell()

Send a message to the actor without waiting for a reply (fire-and-forget).

public tell(T $message) : void

The message is enqueued in the actor's mailbox and processed asynchronously. This method never blocks and always returns immediately.

Parameters
$message : T

        
On this page

Search results