Skip to main content

ActorPool

This item is only intended to be used by the module's authors. Private

Manages a collection of worker Actors and is responsible for distributing work across them.

It handles:

  • Actor creation and lifecycle
  • Worker script cloning and startup
  • Batch-to-actor assignment
  • Message dispatch (tracked and detached)

ActorPool does not collect results or track completion; it is a low-level scheduling and dispatch component used by Bridge.

Functions

Populate

ActorPool:Populate(
workerScript | LocalScript,
actorCountnumber
) → ()

Populates the pool with worker Actors

Each actor:

  • Is created
  • Receives a cloned worker script
  • Starts the worker script immediately

WaitForReplication

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
ActorPool:WaitForReplication() → ()

Waits until all workers report readiness.

This blocks until each Actor sets the ready attribute, which is typically done by calling Kernel:Ready() inside the worker.

This is used to ensure workers are fully initialized before dispatching jobs.

DispatchAll

ActorPool:DispatchAll(
messagestring,--

Message name

...any--

Arguments forwarded to all actors

) → ()

Sends a message to all actors.

This is used for setup or control signals rather than work distribution.

DispatchBatched

ActorPool:DispatchBatched(
messagestring,--

Job name

threadCountnumber,--

Total logical work items

batchSizenumber,--

Items per batch

...any--

Extra arguments forwarded to workers

) → number--

Number of actors used

Dispatches a tracked job in batches across actors.

Work is divided into contiguous ranges and assigned to actors. Each actor receives at most one message containing a contiguous segment of work and is responsible for flushing results.

Returns the number of actors that were assigned work.

DispatchBatchedDetached

ActorPool:DispatchBatchedDetached(
messagestring,
threadCountnumber,--

Total logical work items

batchSizenumber,--

Items per batch

...any--

Extra arguments forwarded to workers

) → ()

Pretty much the same as ActorPool:DispatchBatched but doesn't return anything

Destroy

ActorPool:Destroy() → ()

Destroys all actors

Show raw api
{
    "functions": [
        {
            "name": "Populate",
            "desc": "Populates the pool with worker Actors\n\nEach actor:\n- Is created\n- Receives a cloned worker script\n- Starts the worker script immediately",
            "params": [
                {
                    "name": "worker",
                    "desc": "",
                    "lua_type": "Script | LocalScript"
                },
                {
                    "name": "actorCount",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 46,
                "path": "src/actor-pool.luau"
            }
        },
        {
            "name": "WaitForReplication",
            "desc": "Waits until all workers report readiness.\n\nThis blocks until each Actor sets the ready attribute, which is\ntypically done by calling `Kernel:Ready()` inside the worker.\n\nThis is used to ensure workers are fully initialized before\ndispatching jobs.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "yields": true,
            "source": {
                "line": 74,
                "path": "src/actor-pool.luau"
            }
        },
        {
            "name": "DispatchAll",
            "desc": "Sends a message to all actors.\n\nThis is used for setup or control signals rather than\nwork distribution.",
            "params": [
                {
                    "name": "message",
                    "desc": "Message name",
                    "lua_type": "string"
                },
                {
                    "name": "...",
                    "desc": "Arguments forwarded to all actors",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 94,
                "path": "src/actor-pool.luau"
            }
        },
        {
            "name": "DispatchBatched",
            "desc": "Dispatches a **tracked job** in batches across actors.\n\nWork is divided into contiguous ranges and assigned to actors.\nEach actor receives at most one message containing a contiguous\nsegment of work and is responsible for flushing results.\n\nReturns the number of actors that were assigned work.",
            "params": [
                {
                    "name": "message",
                    "desc": "Job name",
                    "lua_type": "string"
                },
                {
                    "name": "threadCount",
                    "desc": "Total logical work items",
                    "lua_type": "number"
                },
                {
                    "name": "batchSize",
                    "desc": "Items per batch",
                    "lua_type": "number"
                },
                {
                    "name": "...",
                    "desc": "Extra arguments forwarded to workers",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "Number of actors used",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 117,
                "path": "src/actor-pool.luau"
            }
        },
        {
            "name": "DispatchBatchedDetached",
            "desc": "Pretty much the same as [ActorPool:DispatchBatched] but doesn't return anything",
            "params": [
                {
                    "name": "message",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "threadCount",
                    "desc": "Total logical work items",
                    "lua_type": "number"
                },
                {
                    "name": "batchSize",
                    "desc": "Items per batch",
                    "lua_type": "number"
                },
                {
                    "name": "...",
                    "desc": "Extra arguments forwarded to workers",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 171,
                "path": "src/actor-pool.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Destroys all actors",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 204,
                "path": "src/actor-pool.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "ActorPool",
    "desc": "Manages a collection of worker Actors and is responsible\nfor distributing work across them.\n\nIt handles:\n- Actor creation and lifecycle\n- Worker script cloning and startup\n- Batch-to-actor assignment\n- Message dispatch (tracked and detached)\n\nActorPool does **not** collect results or track completion; it is a\nlow-level scheduling and dispatch component used by [Bridge].",
    "private": true,
    "source": {
        "line": 22,
        "path": "src/actor-pool.luau"
    }
}