Scheduler

util Scheduler

A scheduler helps run the main loop by managing scheduled functions, called tasks, after each frame is displayed.

Tasks are either another Scheduler, or a JavaScript functions returning one of the following codes:

  • Scheduler.Event.NEXT: Move onto the next task *without* rendering the scene first.
  • Scheduler.Event.FLIP_REPEAT: Render the scene and repeat the task.
  • Scheduler.Event.FLIP_NEXT: Render the scene and move onto the next task.
  • Scheduler.Event.QUIT: Quit the scheduler.

It is possible to create sub-schedulers, e.g. to handle loops. Sub-schedulers are added to a parent scheduler as a normal task would be by calling scheduler.add(subScheduler).

Conditional branching is also available: scheduler.addConditionalBranches

Constructor

new Scheduler(psychoJS)

Source:
Parameters:
Name Type Description
psychoJS module:core.PsychoJS

the PsychoJS instance

Members

(static, readonly) Event :Symbol

Source:
Properties:
Name Type Description
NEXT Symbol

Move onto the next task without rendering the scene first.

FLIP_REPEAT Symbol

Render the scene and repeat the task.

FLIP_NEXT Symbol

Render the scene and move onto the next task.

QUIT Symbol

Quit the scheduler.

Events.

Type:
  • Symbol

(static, readonly) Status :Symbol

Source:
Properties:
Name Type Description
RUNNING Symbol

The Scheduler is running.

STOPPED Symbol

The Scheduler is stopped.

Status.

Type:
  • Symbol

status

Source:

Get the status of the scheduler.

Methods

add(task, …args)

Source:

Schedule a new task.

Parameters:
Name Type Attributes Description
task Scheduler~Task | Scheduler

the task to be scheduled

args * <repeatable>

arguments for that task

addConditional(condition, thenScheduler, elseScheduler)

Source:

Schedule a series of task or another, based on a condition.

Note: the tasks are sub-schedulers.

Parameters:
Name Type Description
condition Scheduler~Condition

the condition

thenScheduler Scheduler

the Scheduler to be run if the condition is satisfied

elseScheduler Scheduler

the Scheduler to be run if the condition is not satisfied

(async) start()

Source:

Start this scheduler.

Note: tasks are run after each animation frame.

stop()

Source:

Stop this scheduler.

Type Definitions

Condition() → {boolean}

Source:

Condition evaluated when the task is run.

Returns:
Type
boolean

Task(argsopt)

Source:

Task to be run by the scheduler.

Parameters:
Name Type Attributes Description
args * <optional>

optional arguments