Nexus API Reference

FiberRuntime
in package
implements Runtime

FinalYes
Tags
psalm-api

Table of Contents

Interfaces

Runtime
Abstraction over the concurrency backend that powers the actor system.

Methods

__construct()  : mixed
createFutureSlot()  : FutureSlot
Create a lightweight value slot for the ask pattern.
createMailbox()  : Mailbox<string|int, TM>
Create a new mailbox governed by `$config`.
defer()  : void
Hand `$task` to the runtime to run asynchronously, as soon as possible.
isRunning()  : bool
Return `true` if the runtime event loop is currently active.
name()  : string
Return the human-readable name that identifies this runtime implementation.
run()  : void
Start the runtime event loop and block until all actors have shut down.
scheduleOnce()  : Cancellable
Schedule `$callback` to run once after `$delay` has elapsed.
scheduleRepeatedly()  : Cancellable
Schedule `$callback` to run repeatedly, starting after `$initialDelay`.
shutdown()  : void
Initiate a graceful shutdown and wait up to `$timeout` for completion.
sleep()  : void
Suspend the current fiber or coroutine for `$duration`.
spawn()  : string
Spawn a new fiber or coroutine to run `$actorLoop`.
yield()  : void
Cooperatively yield execution to allow other fibers or coroutines to run.

Methods

createFutureSlot()

Create a lightweight value slot for the ask pattern.

public createFutureSlot() : FutureSlot

The caller is responsible for scheduling timeout failures.

Attributes
#[Override]
Return values
FutureSlot

defer()

Hand `$task` to the runtime to run asynchronously, as soon as possible.

public defer(callable $task) : void

Fire-and-forget: unlike spawn(), which models a tracked, long-lived actor loop and returns an identifier, defer() returns nothing — reach for it to kick off a one-shot unit of work without blocking the caller. Unlike scheduleOnce(), it carries no delay. The task runs in the runtime's own execution context (a fiber, a coroutine, or the next deterministic step), so it may cooperatively yield and sleep just like an actor loop.

Parameters
$task : callable
Attributes
#[Override]

isRunning()

Return `true` if the runtime event loop is currently active.

public isRunning() : bool
Attributes
#[Override]
Return values
bool

name()

Return the human-readable name that identifies this runtime implementation.

public name() : string
Attributes
#[Override]
Return values
string

run()

Start the runtime event loop and block until all actors have shut down.

public run() : void

For FiberRuntime this drives the fiber scheduler. For SwooleRuntime this enters the Swoole event loop. Returns only after shutdown() completes.

Attributes
#[Override]

scheduleOnce()

Schedule `$callback` to run once after `$delay` has elapsed.

public scheduleOnce(Duration $delay, callable $callback) : Cancellable

Returns a Cancellable that can be used to abort the pending callback before it fires. The callback is invoked in the runtime's execution context.

Parameters
$delay : Duration
$callback : callable
Attributes
#[Override]
Return values
Cancellable

scheduleRepeatedly()

Schedule `$callback` to run repeatedly, starting after `$initialDelay`.

public scheduleRepeatedly(Duration $initialDelay, Duration $interval, callable $callback) : Cancellable

Subsequent invocations are spaced $interval apart. Returns a Cancellable to stop future invocations.

Parameters
$initialDelay : Duration
$interval : Duration
$callback : callable
Attributes
#[Override]
Return values
Cancellable

shutdown()

Initiate a graceful shutdown and wait up to `$timeout` for completion.

public shutdown(Duration $timeout) : void

Signals all actors to stop, drains pending messages, and exits the event loop.

Parameters
$timeout : Duration
Attributes
#[Override]

sleep()

Suspend the current fiber or coroutine for `$duration`.

public sleep(Duration $duration) : void

Unlike usleep(), this does not block the OS thread — other actors continue to process messages while this one sleeps.

Parameters
$duration : Duration
Attributes
#[Override]

spawn()

Spawn a new fiber or coroutine to run `$actorLoop`.

public spawn(callable $actorLoop) : string

The runtime starts the loop immediately (or schedules it for the next tick) and returns an opaque identifier string for observability.

Parameters
$actorLoop : callable
Attributes
#[Override]
Return values
string

yield()

Cooperatively yield execution to allow other fibers or coroutines to run.

public yield() : void

Called inside actor message loops to prevent one busy actor from starving others.

Attributes
#[Override]
On this page

Search results