Home Manual Reference Source Test Repository
public interface | source

Scheduler

An execution context and a data structure to order tasks and schedule their execution. Provides a notion of (potentially virtual) time, through the now() getter method.

Each unit of work in a Scheduler is called an Action.

interface Scheduler {
  now(): number;
  schedule(work, delay?, state?): Subscription;
  flush(): void;
  active: boolean;
  actions: Action[];
  scheduledId: number;
}

Test:

Member Summary

Public Members
public

The queue of scheduled actions as an array.

public

A flag to indicate whether the Scheduler is currently executing a batch of queued actions.

public

An internal ID used to track the latest asynchronous task such as those coming from setTimeout, setInterval, requestAnimationFrame, and others.

Method Summary

Public Methods
public

flush(): void

Prompt the Scheduler to execute all of its queued actions, therefore clearing its queue.

public

now(): number

A getter method that returns a number representing the current time (at the time this function was called) according to the scheduler's own internal clock.

public

schedule(work: function(state: ?T): ?Subscription, delay: number, state: T): Subscription

Schedules a function, work, for execution.

Public Members

public actions: Action[] source

The queue of scheduled actions as an array.

public active: boolean source

A flag to indicate whether the Scheduler is currently executing a batch of queued actions.

public scheduledId: number source

An internal ID used to track the latest asynchronous task such as those coming from setTimeout, setInterval, requestAnimationFrame, and others.

Public Methods

public flush(): void source

Prompt the Scheduler to execute all of its queued actions, therefore clearing its queue.

Return:

void

public now(): number source

A getter method that returns a number representing the current time (at the time this function was called) according to the scheduler's own internal clock.

Return:

number

A number that represents the current time. May or may not have a relation to wall-clock time. May or may not refer to a time unit (e.g. milliseconds).

public schedule(work: function(state: ?T): ?Subscription, delay: number, state: T): Subscription source

Schedules a function, work, for execution. May happen at some point in the future, according to the delay parameter, if specified. May be passed some context object, state, which will be passed to the work function.

The given arguments will be processed an stored as an Action object in a queue of actions.

Params:

NameTypeAttributeDescription
work function(state: ?T): ?Subscription

A function representing a task, or some unit of work to be executed by the Scheduler.

delay number
  • optional

Time to wait before executing the work, where the time unit is implicit and defined by the Scheduler itself.

state T
  • optional

Some contextual data that the work function uses when called by the Scheduler.

Return:

Subscription

A subscription in order to be able to unsubscribe the scheduled work.