Constructor
new Scheduler(getTimeFunction, optionsopt)
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
getTimeFunction |
function | Function that must return a time in second. |
||||||||||||||||||||||
options |
Object |
<optional> |
{} | default options. Properties
|
- Source:
- See:
Example
import { Scheduler } from 'waves-masters';
const getTime = () => new Date().getTime() / 1000;
const scheduler = new Scheduler(getTime);
const myEngine = {
advanceTime(currentTime) {
console.log(currentTime);
// ask to be called in 1 second
return time + 1;
}
}
const startTime = Math.ceil(getTime());
scheduler.add(myEngine, startTime);
Members
audioTime :Number
Scheduler current audio time according to currentTime
Type:
- Number
- Source:
currentTime :Number
Scheduler current logical time.
Type:
- Number
- Source:
lookahead :Number
scheduler lookahead time (> period)
Type:
- Number
- Source:
period :Number
scheduler (setTimeout) period
Type:
- Number
- Source:
Methods
add(engine, timeopt)
An object implementing the scheduled interface (called engine
) to the
scheduler at an optionally given time.
The advanceTime
method of the engine added to a scheduler will be called
at the given time and with the given time as argument. The advanceTime
method can return a new scheduling time (i.e. the next time when it will
be called) or it can return Infinity to suspend scheduling without removing
the function from the scheduler. A function that does not return a value
(or returns null or 0) is removed from the scheduler and cannot be used as
argument of the methods remove
and resetEngineTime
anymore.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
engine |
TimeEngine | function | Engine to add to the scheduler |
||
time |
Number |
<optional> |
this.currentTime | Engine start time |
- Source:
clear()
Remove all scheduled engines from the scheduler.
- Source:
remove(engine, timeopt)
Remove an engine implementing the scheduled interface that has been
added to the scheduler using the add
method from the scheduler.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
engine |
TimeEngine | Engine to remove from the scheduler |
||
time |
Number |
<optional> |
this.currentTime | Schedule time |
- Source:
resetEngineTime(engine, time)
Reschedule a scheduled an engine implementing the scheduled interface at a given time.
Parameters:
Name | Type | Description |
---|---|---|
engine |
TimeEngine | Engine to reschedule |
time |
Number | Schedule time |
- Source: