Timed events are delayed callbacks, scheduled using setTimeout or setInterval. This module offers variants of setTimeout, clearTimeout, setInterval, clearInterval, and reset that enforce a synchronous semantics for timed events. Synchronization between timed events entails the following two properties: (1) A timed event that is released from within another timed event that occurred at T=tau, will occur precisely at T=tau+timeout. (2) Any two events t1, t2, with intervals i1, i2, that are released from within the same function will occur precisely at T=tau+i2 and T=tau+i2, respectively. The value of tau will approximate the wallclock time of the first-released event. At common multiples of i1 and i2, t1 and t2 will execute simultenously i.e., in order of their release, and with no logical time elapsing until both have executed. In the rare case the same function happens to execute multiple times consequtively, without some timed event occurring in between, all releases in that series will be scheduled with respect to the same tau. Note that this situation can only arise trough rapidly succeeding asynchronous callbacks. When precise timing is desired, this scenario must be avoided.
WARNING: this implementation will only work correctly if the JavaScript execution environment provides a working implementation of Function.caller. Also see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/caller Function.caller is supported by: Chrome, Firefox Gecko 1.0, IE 8, Opera, Safari, which includes the mobile version of these respective browsers. Function.caller will not work in strict mode.
- Version:
- $Id$
- Source:
- Version:
- $Id$
- Source:
Methods
(inner) CalendarQ()
Construct a new calendar queue.
(inner) CalendarQ()
Construct a new calendar queue.
(inner) Callback(fun, offset, period)
Construct a new Callback object.
Parameters:
Name | Type | Description |
---|---|---|
fun |
||
offset |
||
period |
(inner) Callback(fun, offset, period)
Construct a new Callback object.
Parameters:
Name | Type | Description |
---|---|---|
fun |
||
offset |
||
period |
(inner) clearIntervalSync(cbId)
Unschedule a periodic callback.
Parameters:
Name | Type | Description |
---|---|---|
cbId |
Handle returned by setInterval(). |
(inner) clearIntervalSync(cbId)
Unschedule a periodic callback.
Parameters:
Name | Type | Description |
---|---|---|
cbId |
Handle returned by setInterval(). |
(inner) clearTimeoutSync(cbId)
Unschedule a delayed callback.
Parameters:
Name | Type | Description |
---|---|---|
cbId |
Handle returned by setTimeout(). |
(inner) clearTimeoutSync(cbId)
Unschedule a delayed callback.
Parameters:
Name | Type | Description |
---|---|---|
cbId |
Handle returned by setTimeout(). |
(inner) Event(id, time)
Construct a new Event object.
Parameters:
Name | Type | Description |
---|---|---|
id |
||
time |
(inner) Event(id, time)
Construct a new Event object.
Parameters:
Name | Type | Description |
---|---|---|
id |
||
time |
(inner) reset()
Clear all (period) timed events.
(inner) reset()
Clear all (period) timed events.
(inner) schedule(callback, timeout, caller, repeat)
Schedule a new timed event. This entails adding to the callbacks dictonary, as well as adding it to the calendar queue, and if needed, (re)setting a timer to wake up in time to process enabled events.
Parameters:
Name | Type | Description |
---|---|---|
callback |
The callback to be scheduled. |
|
timeout |
The interval with respect to the current time. |
|
caller |
The function from which this event was released. |
|
repeat |
Whether this timed event is periodic or not. |
Returns:
the id of the event.
(inner) schedule(callback, timeout, caller, repeat)
Schedule a new timed event. This entails adding to the callbacks dictonary, as well as adding it to the calendar queue, and if needed, (re)setting a timer to wake up in time to process enabled events.
Parameters:
Name | Type | Description |
---|---|---|
callback |
The callback to be scheduled. |
|
timeout |
The interval with respect to the current time. |
|
caller |
The function from which this event was released. |
|
repeat |
Whether this timed event is periodic or not. |
Returns:
the id of the event.
(inner) setIntervalSync(callback, timeout)
Schedule a periodic timed event.
Parameters:
Name | Type | Description |
---|---|---|
callback |
The function to be executed. |
|
timeout |
The interval with respect to the (re)current time. |
Returns:
the unique id of the setInterval call.
(inner) setIntervalSync(callback, timeout)
Schedule a periodic timed event.
Parameters:
Name | Type | Description |
---|---|---|
callback |
The function to be executed. |
|
timeout |
The interval with respect to the (re)current time. |
Returns:
the unique id of the setInterval call.
(inner) setTimeoutSync(callback, timeout)
Schedule a timed event.
Parameters:
Name | Type | Description |
---|---|---|
callback |
The function to be executed. |
|
timeout |
The interval with respect to the (re)current time. |
Returns:
the unique id of setTimeout call
(inner) setTimeoutSync(callback, timeout)
Schedule a timed event.
Parameters:
Name | Type | Description |
---|---|---|
callback |
The function to be executed. |
|
timeout |
The interval with respect to the (re)current time. |
Returns:
the unique id of setTimeout call
(inner) tick()
Wake up and process enabled events.
(inner) tick()
Wake up and process enabled events.