Represents a unit of work that can be scheduled to run during a specific stage of the SDK's update cycle.

Tasks may be:

  • repeating — automatically executed every update cycle
  • non-repeating — executed only when explicitly scheduled

A task is managed by an SDKTaskRunner, which handles scheduling and invoking tasks at their designated stage.


// Create a repeating task within the
// input collection stage of the SDK's update cycle. The task
// will run automatically every update cycle.

const myTask = new SDKTask({
name: "MyTask",
stage: SDKTask.CollectInputStage,
task: () => {
console.log("Running my task");
},
repeat: true
});

// Schedule a non-repeating task within the
// animation stage of the SDK's update cycle.

const oneTimeTask = new SDKTask({
name: "OneTimeTask",
stage: SDKTask.AnimateStage,
task: () => {
console.log("Running one-time task");
},
repeat: false
});

// Manually schedule the one-time task to run. We can also
// reschedule it later if needed.
oneTimeTask.schedule();

SDKTaskRunner

Constructors

  • Creates a new SDKTask.

    Parameters

    • params: {
          name?: string;
          repeat?: boolean;
          stage: number;
          task: () => void;
          taskRunner?: SDKTaskRunner;
      }

      Configuration options for the task.

      • Optionalname?: string

        Optional display name for debugging.

      • Optionalrepeat?: boolean

        If true, the task will run every update cycle.

      • stage: number

        The update stage in which this task should run.

      • task: () => void

        The function to execute when the task runs.

      • OptionaltaskRunner?: SDKTaskRunner

        Optional task runner; defaults to the global runner.

    Returns SDKTask

Properties

destroyed: boolean

Whether this task has been destroyed and should no longer run.

name?: string

Optional human-readable identifier useful for debugging and profiling.

repeating: boolean

If true, this task runs every update cycle without needing to be manually scheduled.

scheduled: boolean

Whether this task is currently scheduled to run. Non-repeating tasks must be scheduled before they will execute.

stage: number

The update stage in which this task should run. Must be one of the static stage constants.

task: () => void

The function invoked when this task is executed. Implementations should be side-effecting and synchronous.

taskRunner: SDKTaskRunner

The SDKTaskRunner responsible for managing this task.

AnimateStage: 1

Stage at which tasks perform animation updates.

CollectInputStage: 0

Stage at which tasks handle input collection or preprocessing.

ComputeStage: 2

Stage at which tasks perform compute or simulation work.

PostRenderStage: 4

Stage at which tasks run after rendering is complete.

RenderStage: 3

Stage at which tasks perform rendering-related updates.

Methods

  • Permanently destroys this task.

    A destroyed task:

    • will no longer be scheduled,
    • will no longer run,
    • releases its reference to the task runner.

    Returns void

  • Schedules this task to run during its update stage.

    Non-repeating tasks must be scheduled to execute, while repeating tasks ignore manual scheduling.

    Returns void