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;
}
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 |
Method Summary
Public Methods | ||
public |
flush(): void Prompt the Scheduler to execute all of its queued actions, therefore clearing its queue. |
|
public |
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, |
Public Members
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:
Name | Type | Attribute | Description |
work | function(state: ?T): ?Subscription | A function representing a task, or some unit of work to be executed by the Scheduler. |
|
delay | number |
|
Time to wait before executing the work, where the time unit is implicit and defined by the Scheduler itself. |
state | T |
|
Some contextual data that the |