Holds a callback function to be executed at a specified time; used with Clock. ClockTasks are scheduled as a side effect of Clock methods such as setTime(), resume(), addTask(). ClockTasks are cancelled as a side effect of Clock methods such as pause(), removeTask().

Here is an example of a ClockTask that restarts the simulation every 5 seconds. This script can be entered in the command-line Terminal. For example in Single Spring App

var task = () => sim.reset();
clock.addTask(new ClockTask(5, task));
sim.reset();

Example of a ClockTask that pauses the Clock after 5 seconds:

var task = new ClockTask(5, () => clock.pause());
clock.addTask(task);
sim.reset();

Example of a ClockTask that slows the time rate the Clock after 5 seconds:

var task = new ClockTask(5, () => clock.setTimeRate(0.1));
clock.addTask(task);
sim.reset();

See Clock section Types of Time about clock time and system time.

Constructors

  • Parameters

    • time: number

      the clock time in seconds when the callBack should start

    • callBack: null | (() => void)

      the function to execute at the given clock time

    • Optional opt_sysClock: SystemClock

      a SystemClock to use for this Clock (optional)

    Returns ClockTask

Properties

callBack_: null | (() => void)

the function to execute at the given clock time

Type declaration

    • (): void
    • Returns void

time_: number

the clock time in seconds when the callBack should start

timeoutID_: number = NaN

the ID for cancelling the callback, or NaN if not currently scheduled

Methods

  • Returns the clock time in seconds when the task should be executed.

    Returns number

    the clock time in seconds when the task should be executed

  • Schedules the task to be executed after given time delay in seconds of system time

    Parameters

    • delay: number

      time delay till execution in seconds of system time

    Returns void

  • Set the callback to execute.

    Parameters

    • callBack: null | (() => void)

      the function to execute

    Returns void

Generated using TypeDoc