Skip to main content

Dispatcher

The public interface used to execute parallel jobs.

It provides multiple dispatch modes:

  • Tracked: collect results and invoke a callback
  • Detached: fire-and-forget execution with no results

And these dispatch modes may be immediate or deferred.

The Dispatcher itself is serial; parallelism is handled by the Kernel

Functions

new

Dispatcher.new(
actorCountnumber,--

Number of worker actors

workerScriptScript | LocalScript--

Worker entry script

) → Dispatcher

Creates a new Dispatcher.

This spawns a pool of worker actors using the provided worker script and initializes the internal bridge.

Dispatch

Dispatcher:Dispatch(
namestring,--

Job name

threadCountnumber,--

Total logical work items

callbackfunction,--

(buf: { any }) -> ()

batchSizenumber?,--

Optional batch size override

...any--

Extra arguments forwarded to workers

) → ()

Dispatches a tracked job.

The job:

  • Is split into batches
  • Executed in parallel
  • Returns results into a contiguous table buffer
  • Invokes the callback once all work completes

This is the standard for intensive computation jobs with no side-effects.

DispatchDeferred

Dispatcher:DispatchDeferred(
namestring,--

Job name

threadCountnumber,--

Total logical work items

callbackfunction,--

(buf: { any }) -> ()

batchSizenumber?,--

Optional batch size override

...any--

Extra arguments forwarded to workers

) → ()

Deferred proxy to Dispatcher:Dispatch

DispatchDetached

Dispatcher:DispatchDetached(
namestring,--

Job name

threadCountnumber,--

Total logical work items

_batchSizenumber?,--

Optional batch size override

...any
) → ()

Dispatches a detached job.

The job:

  • Is split into batches
  • Executed in parallel

This is the lowest-overhead mode and is suitable for pure side-effect jobs such as raycasts, writes, or simulation steps.

DispatchDetachedDeferred

Dispatcher:DispatchDetachedDeferred(
namestring,--

Job name

threadCountnumber,--

Total logical work items

_batchSizenumber?,--

Optional batch size override

...any
) → ()

Deferred proxy to Dispatcher:DispatchDetached

Destroy

Dispatcher:Destroy() → ()
Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates a new Dispatcher.\n\nThis spawns a pool of worker actors using the provided worker script\nand initializes the internal bridge.",
            "params": [
                {
                    "name": "actorCount",
                    "desc": "Number of worker actors",
                    "lua_type": "number"
                },
                {
                    "name": "workerScript",
                    "desc": "Worker entry script",
                    "lua_type": "Script | LocalScript"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Dispatcher"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 32,
                "path": "src/dispatcher.luau"
            }
        },
        {
            "name": "Dispatch",
            "desc": "Dispatches a **tracked job**.\n\nThe job:\n- Is split into batches\n- Executed in parallel\n- Returns results into a contiguous table buffer\n- Invokes the callback once all work completes\n\nThis is the standard for intensive computation jobs with no side-effects.",
            "params": [
                {
                    "name": "name",
                    "desc": "Job name",
                    "lua_type": "string"
                },
                {
                    "name": "threadCount",
                    "desc": "Total logical work items",
                    "lua_type": "number"
                },
                {
                    "name": "callback",
                    "desc": "`(buf: { any }) -> ()`",
                    "lua_type": "function"
                },
                {
                    "name": "batchSize",
                    "desc": "Optional batch size override",
                    "lua_type": "number?"
                },
                {
                    "name": "...",
                    "desc": "Extra arguments forwarded to workers",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 55,
                "path": "src/dispatcher.luau"
            }
        },
        {
            "name": "DispatchDeferred",
            "desc": "Deferred proxy to [Dispatcher:Dispatch]",
            "params": [
                {
                    "name": "name",
                    "desc": "Job name",
                    "lua_type": "string"
                },
                {
                    "name": "threadCount",
                    "desc": "Total logical work items",
                    "lua_type": "number"
                },
                {
                    "name": "callback",
                    "desc": "`(buf: { any }) -> ()`",
                    "lua_type": "function"
                },
                {
                    "name": "batchSize",
                    "desc": "Optional batch size override",
                    "lua_type": "number?"
                },
                {
                    "name": "...",
                    "desc": "Extra arguments forwarded to workers",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 75,
                "path": "src/dispatcher.luau"
            }
        },
        {
            "name": "DispatchDetached",
            "desc": "Dispatches a **detached job**.\n\nThe job:\n- Is split into batches\n- Executed in parallel\n\nThis is the lowest-overhead mode and is suitable for pure side-effect jobs \nsuch as raycasts, writes, or simulation steps.",
            "params": [
                {
                    "name": "name",
                    "desc": "Job name",
                    "lua_type": "string"
                },
                {
                    "name": "threadCount",
                    "desc": "Total logical work items",
                    "lua_type": "number"
                },
                {
                    "name": "_batchSize",
                    "desc": "Optional batch size override",
                    "lua_type": "number?"
                },
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 103,
                "path": "src/dispatcher.luau"
            }
        },
        {
            "name": "DispatchDetachedDeferred",
            "desc": "Deferred proxy to [Dispatcher:DispatchDetached]",
            "params": [
                {
                    "name": "name",
                    "desc": "Job name",
                    "lua_type": "string"
                },
                {
                    "name": "threadCount",
                    "desc": "Total logical work items",
                    "lua_type": "number"
                },
                {
                    "name": "_batchSize",
                    "desc": "Optional batch size override",
                    "lua_type": "number?"
                },
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 124,
                "path": "src/dispatcher.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 139,
                "path": "src/dispatcher.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Dispatcher",
    "desc": "The public interface used to execute parallel jobs.\n\nIt provides multiple dispatch modes:\n- **Tracked**: collect results and invoke a callback\n- **Detached**: fire-and-forget execution with no results\n\nAnd these dispatch modes may be immediate or deferred.\n\nThe Dispatcher itself is serial; parallelism is handled \nby the [Kernel]",
    "source": {
        "line": 17,
        "path": "src/dispatcher.luau"
    }
}