Nexus API Reference

WorkerPoolApp
in package
implements WorkerStartHandler

AbstractYes
Tags
psalm-api

High-level entry point for worker pool applications. Mirrors NexusApp.

Extend this class and override configure() to spawn actors per worker. Call the static run() to boot the pool — identical to NexusApp::run().

Usage:

final class MyApp extends WorkerPoolApp
{
    protected function configure(WorkerNode $node): void
    {
        $node->spawn(Props::fromBehavior($orderBehavior), 'orders');
        $node->spawn(Props::fromFactory(fn() => new PaymentActor()), 'payments');
    }
}

MyApp::run(WorkerPoolConfig::withThreads(8));

Thread safety: configure() runs fresh in each thread. Closures used inside configure() are constructed per-thread — no cross-thread serialization needed.

Table of Contents

Interfaces

WorkerStartHandler

Methods

onWorkerStart()  : void
run()  : void
Boot the worker pool. Blocks until the pool exits.
configure()  : void
Spawn actors and configure this worker. Called once per thread after the WorkerNode is ready. Safe to use closures and object instantiation.

Methods

run()

Boot the worker pool. Blocks until the pool exits.

public final static run(WorkerPoolConfig $config) : void

Passes static::class (a string) to the bootstrap so no closures cross thread boundaries. Each thread instantiates the subclass fresh.

Parameters
$config : WorkerPoolConfig

configure()

Spawn actors and configure this worker. Called once per thread after the WorkerNode is ready. Safe to use closures and object instantiation.

protected abstract configure(WorkerNode $node) : void
Parameters
$node : WorkerNode

        
On this page

Search results