Skip to main content

Bridge

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

The intermediary between the serial Dispatcher and the parallel Kernel.

It is responsible for:

  • Dispatching jobs to actors
  • Tracking job completion
  • Collecting and merging results
  • Invoking completion callbacks

Functions

new

Bridge.new(
actorCountnumber,--

Number of worker actors

workerScriptScript | LocalScript--

Worker entry script

) → Bridge

Creates a new Bridge.

This creates an ActorPool, spawns workers, and establishes the BindableEvent internal messaging channel used to receive job results.

Send

Bridge:Send(
namestring,--

Job name

threadCountnumber,--

Total logical work items

batchSizenumber,--

Items per batch

buf{any},--

Output buffer

callbackfunction,--

Invoked once all batches complete

...any--

Extra arguments forwarded to workers

) → ()

Dispatches a tracked job to the ActorPool.

The job:

  • Is split into batches
  • Executed in parallel
  • Sends results back to the bridge
  • Invokes the callback once all batches complete

This is the tracked dispatch used by Dispatcher:Dispatch and Dispatcher:DispatchDeferred.

Errors

TypeDescription
"reqId collision"Too much jobs registered

SendDetached

Bridge:SendDetached(
namestring,--

Job name

threadCountnumber,--

Total logical work items

batchSizenumber,--

Items per batch

...any--

Extra arguments forwarded to workers

) → ()

Dispatches a detached job to the ActorPool.

The job:

  • Is split into batches
  • Executed in parallel

This is the detached dispatch used by Dispatcher:DispatchDetached and Dispatcher:DispatchDetachedDeferred.

Destroy

Bridge:Destroy() → ()

Destroys the messenger bindable, the ActorPool, and clears the registry

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates a new Bridge.\n\nThis creates an [ActorPool], spawns workers, and establishes\nthe [BindableEvent] internal messaging channel used to receive job results.",
            "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": "Bridge"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 37,
                "path": "src/bridge.luau"
            }
        },
        {
            "name": "Send",
            "desc": "Dispatches a **tracked job** to the [ActorPool].\n\nThe job:\n- Is split into batches\n- Executed in parallel\n- Sends results back to the bridge\n- Invokes the callback once all batches complete\n\nThis is the tracked dispatch used by\n`Dispatcher:Dispatch` and `Dispatcher:DispatchDeferred`.",
            "params": [
                {
                    "name": "name",
                    "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": "buf",
                    "desc": "Output buffer",
                    "lua_type": "{ any }"
                },
                {
                    "name": "callback",
                    "desc": "Invoked once all batches complete",
                    "lua_type": "function"
                },
                {
                    "name": "...",
                    "desc": "Extra arguments forwarded to workers",
                    "lua_type": "any"
                }
            ],
            "returns": [],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "\"reqId collision\"",
                    "desc": "Too much jobs registered"
                }
            ],
            "source": {
                "line": 98,
                "path": "src/bridge.luau"
            }
        },
        {
            "name": "SendDetached",
            "desc": "Dispatches a **detached job** to the [ActorPool].\n\nThe job:\n- Is split into batches\n- Executed in parallel\n\nThis is the detached dispatch used by\n`Dispatcher:DispatchDetached` and `Dispatcher:DispatchDetachedDeferred`.",
            "params": [
                {
                    "name": "name",
                    "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": [],
            "function_type": "method",
            "source": {
                "line": 137,
                "path": "src/bridge.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Destroys the messenger bindable, the [ActorPool], and clears the registry",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 147,
                "path": "src/bridge.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Bridge",
    "desc": "The intermediary between the serial [Dispatcher] and the\nparallel [Kernel].\n\nIt is responsible for:\n- Dispatching jobs to actors\n- Tracking job completion\n- Collecting and merging results\n- Invoking completion callbacks",
    "private": true,
    "source": {
        "line": 20,
        "path": "src/bridge.luau"
    }
}