Skip to main content

Scheduler

An Object which handles scheduling Systems to run within different Phases. The order of which Systems run will be defined either implicitly by when it was added, or explicitly by tagging the system with a Phase.

Types​

SystemFn​

type SystemFn = ((U...) → any)

SystemTable​

interface SystemTable {
system: SystemFn<U...>
phase: Phase?
[any]: any
}

System​

type System = SystemFn<U...> | SystemTable<U...>

Functions​

new​

Scheduler.new(args: U...) → ()

Creates a new Scheduler, the args passed will be passed to any System anytime it is ran by the Scheduler.

addPlugin​

Scheduler:addPlugin(plugin: PlanckPlugin) → ()

Initializes a plugin with the scheduler, see the Plugin Docs for more information.

getDeltaTime​

Scheduler:getDeltaTime() → number

Returns the time since the system was ran last. This must be used within a registered system.

run​

Scheduler:run(phase: Phase) → Scheduler

Runs all Systems tagged with the Phase in order.

run​

Scheduler:run(pipeline: Pipeline) → Scheduler

Runs all Systems tagged with any Phase within the Pipeline in order.

run​

Scheduler:run(system: System) → Scheduler

Runs the System, passing in the arguments of the Scheduler, U....

runAll​

Scheduler:runAll() → Scheduler

Runs all Systems within order.

NOTE

When you add a Pipeline or Phase with an event, it will be grouped with other Pipelines/Phases on that event. Otherwise, it will be added to the default group. When not running systems on Events, such as with the runAll method, the Default group will be ran first, and then each Event Group in the order created. Pipelines/Phases in these groups are still ordered by their dependencies and by the order of insertion.

insert​

Scheduler:insert(phase: Phase) → Scheduler

Initializes the Phase within the Scheduler, ordering it implicitly by setting it as a dependent of the previous Phase/Pipeline.

insert​

Scheduler:insert(pipeline: Pipeline) → Scheduler

Initializes the Pipeline and it's Phases within the Scheduler, ordering the Pipeline implicitly by setting it as a dependent of the previous Phase/Pipeline.

insert​

Scheduler:insert(
phase: Phase,
instance: Instance | EventLike,
event: string | EventLike
) → Scheduler

Initializes the Phase within the Scheduler, ordering it implicitly by setting it as a dependent of the previous Phase/Pipeline, and scheduling it to be ran on the specified event.

local myScheduler = Scheduler.new()
    :insert(myPhase, RunService, "Heartbeat")

insert​

Scheduler:insert(
pipeline: Pipeline,
instance: Instance | EventLike,
event: string | EventLike
) → Scheduler

Initializes the Pipeline and it's Phases within the Scheduler, ordering the Pipeline implicitly by setting it as a dependent of the previous Phase/Pipeline, and scheduling it to be ran on the specified event.

local myScheduler = Scheduler.new()
    :insert(myPipeline, RunService, "Heartbeat")

insertAfter​

Scheduler:insertAfter(
phase: Phase,
after: Phase | Pipeline
) → Scheduler

Initializes the Phase within the Scheduler, ordering it explicitly by setting the after Phase/Pipeline as a dependent.

insertAfter​

Scheduler:insertAfter(
pipeline: Pipeline,
after: Phase | Pipeline
) → Scheduler

Initializes the Pipeline and it's Phases within the Scheduler, ordering the Pipeline explicitly by setting the after Phase/Pipeline as a dependent.

insertBefore​

Scheduler:insertBefore(
phase: Phase,
before: Phase | Pipeline
) → Scheduler

Initializes the Phase within the Scheduler, ordering it explicitly by setting the before Phase/Pipeline as a dependency.

insertBefore​

Scheduler:insertBefore(
pipeline: Pipeline,
before: Phase | Pipeline
) → Scheduler

Initializes the Pipeline and it's Phases within the Scheduler, ordering the Pipeline explicitly by setting the before Phase/Pipeline as a dependency.

addSystems​

Scheduler:addSystems(
systems: System,
phase: Phase?
) → ()

Adds the System to the Scheduler, scheduling it to be ran implicitly within the provided Phase or on the default Main phase.

addSystems​

Scheduler:addSystems(
systems: {System},
phase: Phase?
) → ()

Adds the Systems to the Scheduler, scheduling them to be ran implicitly within the provided Phase or on the default Main phase.

editSystem​

Scheduler:editSystem(
system: System,
newPhase: Phase
) → ()

Changes the Phase that this system is scheduled on.

removeSystem​

Scheduler:removeSystem(system: System) → ()

Removes the System from the Scheduler.

replaceSystem​

Scheduler:replaceSystem(
old: System,
new: System
) → ()

Replaces the System with a new System.

addRunCondition​

Scheduler:addRunCondition(
system: System,
fn: (U...) → boolean
) → ()

Adds a Run Condition which the Scheduler will check before this System is ran.

addRunCondition​

Scheduler:addRunCondition(
phase: Phase,
fn: (U...) → boolean
) → ()

Adds a Run Condition which the Scheduler will check before any Systems within this Phase are ran.

addRunCondition​

Scheduler:addRunCondition(
pipeline: Pipeline,
fn: (U...) → boolean
) → ()

Adds a Run Condition which the Scheduler will check before any Systems within any Phases apart of this Pipeline are ran.\

cleanup​

Scheduler:cleanup() → ()

Disconnects all events, closes all threads, and performs other cleanup work.

DANGER

Only use this if you intend to not use the associated Scheduler anymore. It will not work as intended. You should dereference the scheduler object so that it may be garbage collected.

WARNING

If you're creating a "throwaway" scheduler, you should not add plugins like Jabby or the Matter Debugger to it. These plugins are unable to properly be cleaned up, use them with caution.

Show raw api
{
    "functions": [
        {
            "name": "addPlugin",
            "desc": "Initializes a plugin with the scheduler, see the [Plugin Docs](/docs/plugins) for more information.\r",
            "params": [
                {
                    "name": "plugin",
                    "desc": "",
                    "lua_type": "PlanckPlugin"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 51,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "getDeltaTime",
            "desc": "Returns the time since the system was ran last.\nThis must be used within a registered system.\r",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 68,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "run",
            "desc": "Runs all Systems tagged with the Phase in order.\r",
            "params": [
                {
                    "name": "phase",
                    "desc": "",
                    "lua_type": "Phase"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Scheduler"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 267,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "run",
            "desc": "Runs all Systems tagged with any Phase within the Pipeline in order.\r",
            "params": [
                {
                    "name": "pipeline",
                    "desc": "",
                    "lua_type": "Pipeline"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Scheduler"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 274,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "run",
            "desc": "Runs the System, passing in the arguments of the Scheduler, `U...`.\r",
            "params": [
                {
                    "name": "system",
                    "desc": "",
                    "lua_type": "System"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Scheduler"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 281,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "runAll",
            "desc": "Runs all Systems within order.\n:::note\nWhen you add a Pipeline or Phase with an event, it will be grouped\nwith other Pipelines/Phases on that event. Otherwise, it will be\nadded to the default group.\nWhen not running systems on Events, such as with the `runAll` method,\nthe Default group will be ran first, and then each Event Group in the\norder created.\nPipelines/Phases in these groups are still ordered by their dependencies\nand by the order of insertion.\n:::\r",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Scheduler"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 320,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "insert",
            "desc": "Initializes the Phase within the Scheduler, ordering it implicitly by\nsetting it as a dependent of the previous Phase/Pipeline.\r",
            "params": [
                {
                    "name": "phase",
                    "desc": "",
                    "lua_type": "Phase"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Scheduler"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 352,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "insert",
            "desc": "Initializes the Pipeline and it's Phases within the Scheduler,\nordering the Pipeline implicitly by setting it as a dependent\nof the previous Phase/Pipeline.\r",
            "params": [
                {
                    "name": "pipeline",
                    "desc": "",
                    "lua_type": "Pipeline"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Scheduler"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 361,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "insert",
            "desc": "Initializes the Phase within the Scheduler, ordering it implicitly\nby setting it as a dependent of the previous Phase/Pipeline, and\nscheduling it to be ran on the specified event.\n```lua\nlocal myScheduler = Scheduler.new()\n    :insert(myPhase, RunService, \"Heartbeat\")\n```\r",
            "params": [
                {
                    "name": "phase",
                    "desc": "",
                    "lua_type": "Phase"
                },
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance | EventLike"
                },
                {
                    "name": "event",
                    "desc": "",
                    "lua_type": "string | EventLike"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Scheduler"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 377,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "insert",
            "desc": "Initializes the Pipeline and it's Phases within the Scheduler,\nordering the Pipeline implicitly by setting it as a dependent of\nthe previous Phase/Pipeline, and scheduling it to be ran on the\nspecified event.\n```lua\nlocal myScheduler = Scheduler.new()\n    :insert(myPipeline, RunService, \"Heartbeat\")\n```\r",
            "params": [
                {
                    "name": "pipeline",
                    "desc": "",
                    "lua_type": "Pipeline"
                },
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance | EventLike"
                },
                {
                    "name": "event",
                    "desc": "",
                    "lua_type": "string | EventLike"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Scheduler"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 394,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "insertAfter",
            "desc": "Initializes the Phase within the Scheduler, ordering it\nexplicitly by setting the after Phase/Pipeline as a dependent.\r",
            "params": [
                {
                    "name": "phase",
                    "desc": "",
                    "lua_type": "Phase"
                },
                {
                    "name": "after",
                    "desc": "",
                    "lua_type": "Phase | Pipeline"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Scheduler"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 430,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "insertAfter",
            "desc": "Initializes the Pipeline and it's Phases within the Scheduler,\nordering the Pipeline explicitly by setting the after Phase/Pipeline\nas a dependent.\r",
            "params": [
                {
                    "name": "pipeline",
                    "desc": "",
                    "lua_type": "Pipeline"
                },
                {
                    "name": "after",
                    "desc": "",
                    "lua_type": "Phase | Pipeline"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Scheduler"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 440,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "insertBefore",
            "desc": "Initializes the Phase within the Scheduler, ordering it\nexplicitly by setting the before Phase/Pipeline as a dependency.\r",
            "params": [
                {
                    "name": "phase",
                    "desc": "",
                    "lua_type": "Phase"
                },
                {
                    "name": "before",
                    "desc": "",
                    "lua_type": "Phase | Pipeline"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Scheduler"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 470,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "insertBefore",
            "desc": "Initializes the Pipeline and it's Phases within the Scheduler,\nordering the Pipeline explicitly by setting the before Phase/Pipeline\nas a dependency.\r",
            "params": [
                {
                    "name": "pipeline",
                    "desc": "",
                    "lua_type": "Pipeline"
                },
                {
                    "name": "before",
                    "desc": "",
                    "lua_type": "Phase | Pipeline"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Scheduler"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 480,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "addSystems",
            "desc": "Adds the System to the Scheduler, scheduling it to be ran\nimplicitly within the provided Phase or on the default Main phase.\r",
            "params": [
                {
                    "name": "systems",
                    "desc": "",
                    "lua_type": "System"
                },
                {
                    "name": "phase",
                    "desc": "",
                    "lua_type": "Phase?"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 509,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "addSystems",
            "desc": "Adds the Systems to the Scheduler, scheduling them to be ran\nimplicitly within the provided Phase or on the default Main phase.\r",
            "params": [
                {
                    "name": "systems",
                    "desc": "",
                    "lua_type": "{ System }"
                },
                {
                    "name": "phase",
                    "desc": "",
                    "lua_type": "Phase?"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 562,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "editSystem",
            "desc": "Changes the Phase that this system is scheduled on.\r",
            "params": [
                {
                    "name": "system",
                    "desc": "",
                    "lua_type": "System"
                },
                {
                    "name": "newPhase",
                    "desc": "",
                    "lua_type": "Phase"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 597,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "removeSystem",
            "desc": "Removes the System from the Scheduler.\r",
            "params": [
                {
                    "name": "system",
                    "desc": "",
                    "lua_type": "System"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 643,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "replaceSystem",
            "desc": "Replaces the System with a new System.\r",
            "params": [
                {
                    "name": "old",
                    "desc": "",
                    "lua_type": "System"
                },
                {
                    "name": "new",
                    "desc": "",
                    "lua_type": "System"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 678,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "addRunCondition",
            "desc": "Adds a Run Condition which the Scheduler will check before\nthis System is ran.\r",
            "params": [
                {
                    "name": "system",
                    "desc": "",
                    "lua_type": "System"
                },
                {
                    "name": "fn",
                    "desc": "",
                    "lua_type": "(U...) -> boolean"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 720,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "addRunCondition",
            "desc": "Adds a Run Condition which the Scheduler will check before\nany Systems within this Phase are ran.\r",
            "params": [
                {
                    "name": "phase",
                    "desc": "",
                    "lua_type": "Phase"
                },
                {
                    "name": "fn",
                    "desc": "",
                    "lua_type": "(U...) -> boolean"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 728,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "addRunCondition",
            "desc": "Adds a Run Condition which the Scheduler will check before\nany Systems within any Phases apart of this Pipeline are ran.\\\r",
            "params": [
                {
                    "name": "pipeline",
                    "desc": "",
                    "lua_type": "Pipeline"
                },
                {
                    "name": "fn",
                    "desc": "",
                    "lua_type": "(U...) -> boolean"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 736,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "cleanup",
            "desc": "Disconnects all events, closes all threads, and performs\nother cleanup work.\n:::danger\nOnly use this if you intend to not use the associated\nScheduler anymore. It will not work as intended.\nYou should dereference the scheduler object so that\nit may be garbage collected.\n:::\n:::warning\nIf you're creating a \"throwaway\" scheduler, you should\nnot add plugins like Jabby or the Matter Debugger to it.\nThese plugins are unable to properly be cleaned up, use\nthem with caution.\n:::\r",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 848,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "new",
            "desc": "Creates a new Scheduler, the args passed will be passed to\nany System anytime it is ran by the Scheduler.\r",
            "params": [
                {
                    "name": "args",
                    "desc": "",
                    "lua_type": "U..."
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 876,
                "path": "src/planck/src/Scheduler.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "SystemFn",
            "desc": "",
            "lua_type": "((U...) -> any)",
            "source": {
                "line": 25,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "SystemTable",
            "desc": "",
            "fields": [
                {
                    "name": "system",
                    "lua_type": "SystemFn<U...>",
                    "desc": ""
                },
                {
                    "name": "phase",
                    "lua_type": "Phase?",
                    "desc": ""
                },
                {
                    "name": "[any]",
                    "lua_type": "any",
                    "desc": ""
                }
            ],
            "source": {
                "line": 31,
                "path": "src/planck/src/Scheduler.luau"
            }
        },
        {
            "name": "System",
            "desc": "",
            "lua_type": "SystemFn<U...> | SystemTable<U...>",
            "source": {
                "line": 34,
                "path": "src/planck/src/Scheduler.luau"
            }
        }
    ],
    "name": "Scheduler",
    "desc": "An Object which handles scheduling Systems to run within different\nPhases. The order of which Systems run will be defined either\nimplicitly by when it was added, or explicitly by tagging the system\nwith a Phase.\r",
    "source": {
        "line": 41,
        "path": "src/planck/src/Scheduler.luau"
    }
}