Skip to main content

Dispatcher

Responsible for handling and dispatching workers. This should never be created by a worker or in parallel.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ComputeLua = require(ReplicatedStorage.ComputeLua)

local worker = script.Worker
local numWorkers = 256

local Dispatcher = ComputeLua.CreateDispatcher(numWorkers, worker)

Types

BufferDataType

type BufferDataType = Vector2 | Vector3 | CFrame | Color3 | UDim | UDim2 | number | boolean | string

The only data types allowed in buffers

ComputeBufferDataType

type ComputeBufferDataType = {[number]BufferDataType | ComputeBufferDataType}

Type for the data of a ComputeBuffer

Functions

Dispatch

Parallel Unsafe
since v1.3.0
</>
Dispatcher.Dispatch(
selfDispatcher,
threadstring,--

The name of the thread to dispatch, this is the same name as the one in the workers

numThreadsnumber,--

How many times of this thread should be calling

overrideBatchSizenumber?--

(NOT RECOMMENDED) override the default batch size

) → Promise

Dispatch a number of threads to the workers

SetComputeBuffer

Parallel Unsafe
since v1.3.0
</>
Dispatcher.SetComputeBuffer(
selfDispatcher,
bufferNamestring,--

The name of the buffer

bufferDataComputeBufferDataType--

The data to set

) → ()

Set/Create ComputeBuffer data

DestroyComputeBuffer

Parallel Unsafe
since v1.3.0
</>
Dispatcher.DestroyComputeBuffer(
selfDispatcher,
bufferNamestring--

The name of the buffer

) → ()

Delete a ComputeBuffer's data

Destroy

Parallel Unsafe
since v1.0.0
</>
Dispatcher.Destroy(selfDispatcher) → ()

The cleanup function for a Dispatcher. This is important to call to free up memory

Show raw api
{
    "functions": [
        {
            "name": "_new",
            "desc": "Create a Dispatcher",
            "params": [
                {
                    "name": "numWorkers",
                    "desc": "How many workers to create",
                    "lua_type": "number"
                },
                {
                    "name": "worker",
                    "desc": "The worker template to use",
                    "lua_type": "Script | LocalScript"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Dispatcher"
                }
            ],
            "function_type": "static",
            "tags": [
                "Parallel Unsafe"
            ],
            "since": "v1.0.0",
            "private": true,
            "source": {
                "line": 175,
                "path": "src/init.lua"
            }
        },
        {
            "name": "Dispatch",
            "desc": "Dispatch a number of threads to the workers",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Dispatcher"
                },
                {
                    "name": "thread",
                    "desc": "The name of the thread to dispatch, this is the same name as the one in the workers",
                    "lua_type": "string"
                },
                {
                    "name": "numThreads",
                    "desc": "How many times of this thread should be calling",
                    "lua_type": "number"
                },
                {
                    "name": "overrideBatchSize",
                    "desc": "(NOT RECOMMENDED) override the default batch size",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise"
                }
            ],
            "function_type": "static",
            "tags": [
                "Parallel Unsafe"
            ],
            "since": "v1.3.0",
            "source": {
                "line": 221,
                "path": "src/init.lua"
            }
        },
        {
            "name": "SetComputeBuffer",
            "desc": "Set/Create ComputeBuffer data",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Dispatcher"
                },
                {
                    "name": "bufferName",
                    "desc": "The name of the buffer",
                    "lua_type": "string"
                },
                {
                    "name": "bufferData",
                    "desc": "The data to set",
                    "lua_type": "ComputeBufferDataType"
                }
            ],
            "returns": [],
            "function_type": "static",
            "tags": [
                "Parallel Unsafe"
            ],
            "since": "v1.3.0",
            "source": {
                "line": 277,
                "path": "src/init.lua"
            }
        },
        {
            "name": "DestroyComputeBuffer",
            "desc": "Delete a ComputeBuffer's data",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Dispatcher"
                },
                {
                    "name": "bufferName",
                    "desc": "The name of the buffer",
                    "lua_type": "string"
                }
            ],
            "returns": [],
            "function_type": "static",
            "tags": [
                "Parallel Unsafe"
            ],
            "since": "v1.3.0",
            "source": {
                "line": 291,
                "path": "src/init.lua"
            }
        },
        {
            "name": "Destroy",
            "desc": "The cleanup function for a Dispatcher. This is important to call to free up memory",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "Dispatcher"
                }
            ],
            "returns": [],
            "function_type": "static",
            "tags": [
                "Parallel Unsafe"
            ],
            "since": "v1.0.0",
            "source": {
                "line": 302,
                "path": "src/init.lua"
            }
        }
    ],
    "properties": [
        {
            "name": "numWorkers",
            "desc": "",
            "lua_type": "number",
            "private": true,
            "readonly": true,
            "source": {
                "line": 82,
                "path": "src/init.lua"
            }
        },
        {
            "name": "computeBuffers",
            "desc": "",
            "lua_type": "{ [number]: ComputeBufferDataType }",
            "private": true,
            "readonly": true,
            "source": {
                "line": 88,
                "path": "src/init.lua"
            }
        },
        {
            "name": "worker",
            "desc": "",
            "lua_type": "Script | LocalScript",
            "private": true,
            "readonly": true,
            "source": {
                "line": 94,
                "path": "src/init.lua"
            }
        },
        {
            "name": "workerFolder",
            "desc": "",
            "lua_type": "Folder",
            "private": true,
            "readonly": true,
            "source": {
                "line": 100,
                "path": "src/init.lua"
            }
        },
        {
            "name": "workers",
            "desc": "",
            "lua_type": "{Actor}",
            "private": true,
            "readonly": true,
            "source": {
                "line": 106,
                "path": "src/init.lua"
            }
        },
        {
            "name": "workerRemote",
            "desc": "",
            "lua_type": "BindableEvent",
            "private": true,
            "readonly": true,
            "source": {
                "line": 112,
                "path": "src/init.lua"
            }
        }
    ],
    "types": [
        {
            "name": "BufferDataType",
            "desc": "The only data types allowed in buffers",
            "lua_type": "Vector2 | Vector3 | CFrame | Color3 | UDim | UDim2 | number | boolean | string",
            "source": {
                "line": 41,
                "path": "src/init.lua"
            }
        },
        {
            "name": "ComputeBufferDataType",
            "desc": "Type for the data of a ComputeBuffer",
            "lua_type": "{ [number]: BufferDataType | ComputeBufferDataType }",
            "source": {
                "line": 52,
                "path": "src/init.lua"
            }
        }
    ],
    "name": "Dispatcher",
    "desc": "Responsible for handling and dispatching workers. \nThis should never be created by a worker or in parallel.\n\n```lua\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\n\nlocal ComputeLua = require(ReplicatedStorage.ComputeLua)\n\nlocal worker = script.Worker\nlocal numWorkers = 256\n\nlocal Dispatcher = ComputeLua.CreateDispatcher(numWorkers, worker)\n```",
    "source": {
        "line": 33,
        "path": "src/init.lua"
    }
}