Module: @accessors-hosts/common/deterministicTemporalSemantics

This is the implementation of another deterministic temporal semantics.

This module provides Accessors with deterministic temporal semantics, that are aligned with Cape Code's semantics. This module is to be explored by commonHost, so that any swarmlet host will enjoy these features. For this, accessors calls to setTimeout() or setInterval() are binded, respectively, to this module's setTioumetDet() and setIntervalDet(). It is guaranteed that only one timeout (function provided by the host) is pending
at any time and that callbacks will be executing with respect to their
logical clock domains and their relative priority and/or arrival time.

For this implementation, we assume that there is the physical time line, together with many logical time lines. All time lines do not advance the same way. Physical time is continuous and has the same rate, while logical time is updated at particular instances.

Each logical time line is associated with a 'labeled logical clock domains' (LLCD). This allows for defining and implementing logical simultaneity of callbacks execution.

The basic idea is to define each delayed callback with an LLCD. Two delayed callbacks with the same LLCD share the same logical time line. If they have the same logical time execution, then they will execute atomically one after another, such that their arrival order is respected. That is, if the instruction setInterval(F, T, 'A') was called before setInterval(G, T, 'A'), and no other action involving the LLCD 'A' has happened in between, then when F executes, it will be immediately followed by G.

When a call to the binded setTimeout or setInterval occurs, then scheduling the execution will depend on the LLCD. If it is a new one, then a new LLCD is created and its current logical time is set to the current physical time. However, if the LLCD is already defined, then the current logical time of that clock domain is used. In either cases, the callback will execute at its LLCD logical current time plus the timeout. Labeled logical clock domain are strings. However, if the programmer unintentionally or intentionally do not provide one, then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). The new anonymous clock domain is unique and is generated by incrementing defaultLabelIndex. An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

This implementation was preceded by a another one that adopts a slightly different semantics for the execution. In the previous version, any two callbacks with the same label execute starting from the same reference point in time. In addition, there are only two time lines: the physical one and the logical one. Therefore, delayed callbacks execute only with respect to the logical one. This way, the inter execution time is always respected. The drawback is that additional delays are added.

For the purpose of implementing temporal semantics, we record all delayed callBacks in the 'delayedCallbacks' object. This object is accessed by label. Within a labeled object, we record the current logical execution time, and the group of delayed callbacks having the same label. A new delayedCallback object is added to delayedCallbacks, given its label. In addition, each new object is uniquely identified by a number (generated by automatically incrementing cbIdentifier). Consequently, the identifier reflects the order in which the calls to setTimeout or setInterval occurred. This number is returned and is to be used for clearing the corresponding timer. This happens each time setTimeoutDet() or seIntervalDet() is called.

For the sake of any system that may need to define execution order based on predefined/precomputed priorities, it is possible to pass the priority as an argument to setTimeout or setInterval. Consequently, the third level of delayed callbacks ordering will be, first, based on priorities, then on arrival time (reflected by the identifiers). For the case of Accessors, the priority will be inherited from the accessor's priority (if defined).

In order to make the process fast, the list 'callbackQueue' keeps an incremental next execution time sorted list of pointers to the delayed callbacks. Pointers are objects with two attributes: the labeled clock domain and the identifier. This list, has three levels of sorting. The first one is obviously the execution time. If two or more callbacks have the same execution time, they are ordered by their labels origin. This is the second level of sorting. Finally, the third one is the callbacks ordering, reflected by the identifiers.

A delayed callback has the following attributes:

  • callbackFunction: the callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.
  • interval: The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.
  • periodic: if set to true, the callback needs to execute every interval time, otherwise, it executes only once. A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true).
  • nextExecutionTime: records the next time at which the callback should be executed.
  • priority is an optional attribute for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).
  • errorCallback is an optional attribute that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.
  • doneCallback is an optional attribute that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

    Proof: Done! Using Real-Time Maude :-)

Version:
  • $$Id: deterministicTemporalSemantics.js 2017-05-03 11:11:30Z chadlia.jerad $$
Author:
  • Chadlia Jerad and Edward A. Lee
Source:
Version:
  • $$Id: deterministicTemporalSemantics.js 2017-05-03 11:11:30Z chadlia.jerad $$
Author:
  • Chadlia Jerad and Edward A. Lee
Source:
Version:
  • $$Id: deterministicTemporalSemantics.js 2017-05-03 11:11:30Z chadlia.jerad $$
Author:
  • Chadlia Jerad and Edward A. Lee
Source:

Methods

(inner) clearIntervalDet(cbId)

This function is to be binded to clearInterval() function. It clears the periodic timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the cbIndentifier.

Source:

(inner) clearIntervalDet(cbId)

This function is to be binded to clearInterval() function. It clears the periodic timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the cbIndentifier.

Source:

(inner) clearIntervalDet(cbId)

This function is to be binded to clearInterval() function. It clears the periodic timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the cbIndentifier.

Source:

(inner) clearTick(cbId, periodic)

clearTick() parses delayedCallbacks in order to remove the one with the passed id and periodicity. It is also deleted from callbackQueue. If the first argument, that is the identifier, is not a number, than no need to parse.

Parameters:
Name Type Description
cbId

this parameter contains the callback identifier

periodic

boolean value: true if periodic (called from clearIntervalDet), false otherwise

Source:

(inner) clearTick(cbId, periodic)

clearTick() parses delayedCallbacks in order to remove the one with the passed id and periodicity. It is also deleted from callbackQueue. If the first argument, that is the identifier, is not a number, than no need to parse.

Parameters:
Name Type Description
cbId

this parameter contains the callback identifier

periodic

boolean value: true if periodic (called from clearIntervalDet), false otherwise

Source:

(inner) clearTick(cbId, periodic)

clearTick() parses delayedCallbacks in order to remove the one with the passed id and periodicity. It is also deleted from callbackQueue. If the first argument, that is the identifier, is not a number, than no need to parse.

Parameters:
Name Type Description
cbId

this parameter contains the callback identifier

periodic

boolean value: true if periodic (called from clearIntervalDet), false otherwise

Source:

(inner) clearTimeoutDet(cbId)

This function is to be binded to clearTimeout() function. It clears the timeout timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the callback indentifier of the one time delayed callback to clear.

Source:

(inner) clearTimeoutDet(cbId)

This function is to be binded to clearTimeout() function. It clears the timeout timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the callback indentifier of the one time delayed callback to clear.

Source:

(inner) clearTimeoutDet(cbId)

This function is to be binded to clearTimeout() function. It clears the timeout timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the callback indentifier of the one time delayed callback to clear.

Source:

(inner) computeNextSceduledTick()

Compute the next execution time to be scheduled. Since callbacks are sorted in callbackQueue in order of their next execution time, the next execution time of the one on then the top of the list is returned.

Source:
Returns:

the next execution time of the first callback in the sorted list

(inner) computeNextSceduledTick()

Compute the next execution time to be scheduled. Since callbacks are sorted in callbackQueue in order of their next execution time, the next execution time of the one on then the top of the list is returned.

Source:
Returns:

the next execution time of the first callback in the sorted list

(inner) computeNextSceduledTick()

Compute the next execution time to be scheduled. Since callbacks are sorted in callbackQueue in order of their next execution time, the next execution time of the one on then the top of the list is returned.

Source:
Returns:

the next execution time of the first callback in the sorted list

(inner) executeAndSetNextTick()

This function implements callbacks execution and update. It is called only by the host's setTimeout function. All delayed callbacks with next execution time less than the current time will be executing. Consequently, in case the system has accumulated some delay due, or example, to an over running program, all late callbacks will execute, but with respect to the order and atomicity set by the definitions. Next, the list is cleaned from no-more triggerable callbacks. And finally, the next tick is set.

Source:

(inner) executeAndSetNextTick()

This function implements callbacks execution and update. It is called only by the host's setTimeout function. All delayed callbacks with next execution time less than the current time will be executing. Consequently, in case the system has accumulated some delay due, or example, to an over running program, all late callbacks will execute, but with respect to the order and atomicity set by the definitions. Next, the list is cleaned from no-more triggerable callbacks. And finally, the next tick is set.

Source:

(inner) executeAndSetNextTick()

This function implements callbacks execution and update. It is called only by the host's setTimeout function. All delayed callbacks with next execution time less than the current time will be executing. Consequently, in case the system has accumulated some delay due, or example, to an over running program, all late callbacks will execute, but with respect to the order and atomicity set by the definitions. Next, the list is cleaned from no-more triggerable callbacks. And finally, the next tick is set.

Source:

(inner) executeCallbacks()

This function executes delayed callback such that their next execution time is equal to the nextScheduledTick. It then updates the next execution time if the callback is periodic, and remove it if not periodic. Labels are also deleted if the corresponding array is empty.

Source:

(inner) executeCallbacks()

This function executes delayed callback such that their next execution time is equal to the nextScheduledTick. It then updates the next execution time if the callback is periodic, and remove it if not periodic. Labels are also deleted if the corresponding array is empty.

Source:

(inner) executeCallbacks()

This function executes delayed callback such that their next execution time is equal to the nextScheduledTick. It then updates the next execution time if the callback is periodic, and remove it if not periodic. Labels are also deleted if the corresponding array is empty.

Source:

(inner) putInCallbackQueue(label, id)

callbackQueue variable keeps track of an ordered list of callbacks. This variable contains pointers to delayed callbacks, which are objects with two attributes: the label and the id.

This function performs a sorted insertion, given three levels of sorting. The first one is the 'nextExecutionTime'. Then, when two or more callbacks have the same nextExecutionTime, other levels of sorting are considered:

  • Second level of sorting: ascending order of labels (using the value of "origin")
  • Third level: within the same label, delayed callbacks are ordered by priorities first, then by an ascending order of the callback identifiers.
Parameters:
Name Type Description
label

the labeled clock domain of the delayedCallback to add

id

the unique id of of the delayedCallback to add

Source:

(inner) putInCallbackQueue(label, id)

callbackQueue variable keeps track of an ordered list of callbacks. This variable contains pointers to delayed callbacks, which are objects with two attributes: the label and the id.

This function performs a sorted insertion, given three levels of sorting. The first one is the 'nextExecutionTime'. Then, when two or more callbacks have the same nextExecutionTime, other levels of sorting are considered:

  • Second level of sorting: ascending order of labels (using the value of "origin")
  • Third level: within the same label, delayed callbacks are ordered by priorities first, then by an ascending order of the callback identifiers.
Parameters:
Name Type Description
label

the labeled clock domain of the delayedCallback to add

id

the unique id of of the delayedCallback to add

Source:

(inner) putInCallbackQueue(label, id)

callbackQueue variable keeps track of an ordered list of callbacks. This variable contains pointers to delayed callbacks, which are objects with two attributes: the label and the id.

This function performs a sorted insertion, given three levels of sorting. The first one is the 'nextExecutionTime'. Then, when two or more callbacks have the same nextExecutionTime, other levels of sorting are considered:

  • Second level of sorting: ascending order of labels (using the value of "origin")
  • Third level: within the same label, delayed callbacks are ordered by priorities first, then by an ascending order of the callback identifiers.
Parameters:
Name Type Description
label

the labeled clock domain of the delayedCallback to add

id

the unique id of of the delayedCallback to add

Source:

(inner) reset()

In case there are no more delayedCallbacks (that is when callbackQueue becomes empty or delayedCallbacks has no more callbacks, then reset all counter, identifiers, objects and lists.

Source:

(inner) reset()

In case there are no more delayedCallbacks (that is when callbackQueue becomes empty or delayedCallbacks has no more callbacks, then reset all counter, identifiers, objects and lists.

Source:

(inner) reset()

In case there are no more delayedCallbacks (that is when callbackQueue becomes empty or delayedCallbacks has no more callbacks, then reset all counter, identifiers, objects and lists.

Source:

(inner) setDelayedCallback(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

Both, setIntervalDet and setTimeoutDet create a new delayed callback, compute the next execution time, add it to delayedCallbacks and to callbackQueue, and possibly update
the next tick. The only difference if that the first one creates a new delayed callback such that periodic attribute is set to true, while the second creates one with periodic attribute set to false. The following function implements the core common behavior, while setting periodic to the value it should be. Therefore, setIntervalDet and setTimeoutDet just call this function with the right parameters.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback.

(inner) setDelayedCallback(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

Both, setIntervalDet and setTimeoutDet create a new delayed callback, compute the next execution time, add it to delayedCallbacks and to callbackQueue, and possibly update
the next tick. The only difference if that the first one creates a new delayed callback such that periodic attribute is set to true, while the second creates one with periodic attribute set to false. The following function implements the core common behavior, while setting periodic to the value it should be. Therefore, setIntervalDet and setTimeoutDet just call this function with the right parameters.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback.

(inner) setDelayedCallback(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

Both, setIntervalDet and setTimeoutDet create a new delayed callback, compute the next execution time, add it to delayedCallbacks and to callbackQueue, and possibly update
the next tick. The only difference if that the first one creates a new delayed callback such that periodic attribute is set to true, while the second creates one with periodic attribute set to false. The following function implements the core common behavior, while setting periodic to the value it should be. Therefore, setIntervalDet and setTimeoutDet just call this function with the right parameters.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback.

(inner) setIntervalDet(callback, timeout, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setInterval() function. It calls setDelayedCallback since the core function is the same as SetTimeoutDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback

(inner) setIntervalDet(callback, timeout, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setInterval() function. It calls setDelayedCallback since the core function is the same as SetTimeoutDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback

(inner) setIntervalDet(callback, timeout, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setInterval() function. It calls setDelayedCallback since the core function is the same as SetTimeoutDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback

(inner) setTimeoutDet(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setTimeout() function. It calls setDelayedCallback since the core function is the same as SetIntervalDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new one time delayed callback.

(inner) setTimeoutDet(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setTimeout() function. It calls setDelayedCallback since the core function is the same as SetIntervalDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new one time delayed callback.

(inner) setTimeoutDet(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setTimeout() function. It calls setDelayedCallback since the core function is the same as SetIntervalDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new one time delayed callback.

This is the implementation of another deterministic temporal semantics.

This module provides Accessors with deterministic temporal semantics, that are aligned with Cape Code's semantics. This module is to be explored by commonHost, so that any swarmlet host will enjoy these features. For this, accessors calls to setTimeout() or setInterval() are binded, respectively, to this module's setTioumetDet() and setIntervalDet(). It is guaranteed that only one timeout (function provided by the host) is pending
at any time and that callbacks will be executing with respect to their
logical clock domains and their relative priority and/or arrival time.

For this implementation, we assume that there is the physical time line, together with many logical time lines. All time lines do not advance the same way. Physical time is continuous and has the same rate, while logical time is updated at particular instances.

Each logical time line is associated with a 'labeled logical clock domains' (LLCD). This allows for defining and implementing logical simultaneity of callbacks execution.

The basic idea is to define each delayed callback with an LLCD. Two delayed callbacks with the same LLCD share the same logical time line. If they have the same logical time execution, then they will execute atomically one after another, such that their arrival order is respected. That is, if the instruction setInterval(F, T, 'A') was called before setInterval(G, T, 'A'), and no other action involving the LLCD 'A' has happened in between, then when F executes, it will be immediately followed by G.

When a call to the binded setTimeout or setInterval occurs, then scheduling the execution will depend on the LLCD. If it is a new one, then a new LLCD is created and its current logical time is set to the current physical time. However, if the LLCD is already defined, then the current logical time of that clock domain is used. In either cases, the callback will execute at its LLCD logical current time plus the timeout. Labeled logical clock domain are strings. However, if the programmer unintentionally or intentionally do not provide one, then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). The new anonymous clock domain is unique and is generated by incrementing defaultLabelIndex. An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

This implementation was preceded by a another one that adopts a slightly different semantics for the execution. In the previous version, any two callbacks with the same label execute starting from the same reference point in time. In addition, there are only two time lines: the physical one and the logical one. Therefore, delayed callbacks execute only with respect to the logical one. This way, the inter execution time is always respected. The drawback is that additional delays are added.

For the purpose of implementing temporal semantics, we record all delayed callBacks in the 'delayedCallbacks' object. This object is accessed by label. Within a labeled object, we record the current logical execution time, and the group of delayed callbacks having the same label. A new delayedCallback object is added to delayedCallbacks, given its label. In addition, each new object is uniquely identified by a number (generated by automatically incrementing cbIdentifier). Consequently, the identifier reflects the order in which the calls to setTimeout or setInterval occurred. This number is returned and is to be used for clearing the corresponding timer. This happens each time setTimeoutDet() or seIntervalDet() is called.

For the sake of any system that may need to define execution order based on predefined/precomputed priorities, it is possible to pass the priority as an argument to setTimeout or setInterval. Consequently, the third level of delayed callbacks ordering will be, first, based on priorities, then on arrival time (reflected by the identifiers). For the case of Accessors, the priority will be inherited from the accessor's priority (if defined).

In order to make the process fast, the list 'callbackQueue' keeps an incremental next execution time sorted list of pointers to the delayed callbacks. Pointers are objects with two attributes: the labeled clock domain and the identifier. This list, has three levels of sorting. The first one is obviously the execution time. If two or more callbacks have the same execution time, they are ordered by their labels origin. This is the second level of sorting. Finally, the third one is the callbacks ordering, reflected by the identifiers.

A delayed callback has the following attributes:

  • callbackFunction: the callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.
  • interval: The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.
  • periodic: if set to true, the callback needs to execute every interval time, otherwise, it executes only once. A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true).
  • nextExecutionTime: records the next time at which the callback should be executed.
  • priority is an optional attribute for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).
  • errorCallback is an optional attribute that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.
  • doneCallback is an optional attribute that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

    Proof: Done! Using Real-Time Maude :-)

Version:
  • $$Id: deterministicTemporalSemantics.js 2017-05-03 11:11:30Z chadlia.jerad $$
Author:
  • Chadlia Jerad and Edward A. Lee
Source:
Version:
  • $$Id: deterministicTemporalSemantics.js 2017-05-03 11:11:30Z chadlia.jerad $$
Author:
  • Chadlia Jerad and Edward A. Lee
Source:
Version:
  • $$Id: deterministicTemporalSemantics.js 2017-05-03 11:11:30Z chadlia.jerad $$
Author:
  • Chadlia Jerad and Edward A. Lee
Source:

Methods

(inner) clearIntervalDet(cbId)

This function is to be binded to clearInterval() function. It clears the periodic timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the cbIndentifier.

Source:

(inner) clearIntervalDet(cbId)

This function is to be binded to clearInterval() function. It clears the periodic timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the cbIndentifier.

Source:

(inner) clearIntervalDet(cbId)

This function is to be binded to clearInterval() function. It clears the periodic timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the cbIndentifier.

Source:

(inner) clearTick(cbId, periodic)

clearTick() parses delayedCallbacks in order to remove the one with the passed id and periodicity. It is also deleted from callbackQueue. If the first argument, that is the identifier, is not a number, than no need to parse.

Parameters:
Name Type Description
cbId

this parameter contains the callback identifier

periodic

boolean value: true if periodic (called from clearIntervalDet), false otherwise

Source:

(inner) clearTick(cbId, periodic)

clearTick() parses delayedCallbacks in order to remove the one with the passed id and periodicity. It is also deleted from callbackQueue. If the first argument, that is the identifier, is not a number, than no need to parse.

Parameters:
Name Type Description
cbId

this parameter contains the callback identifier

periodic

boolean value: true if periodic (called from clearIntervalDet), false otherwise

Source:

(inner) clearTick(cbId, periodic)

clearTick() parses delayedCallbacks in order to remove the one with the passed id and periodicity. It is also deleted from callbackQueue. If the first argument, that is the identifier, is not a number, than no need to parse.

Parameters:
Name Type Description
cbId

this parameter contains the callback identifier

periodic

boolean value: true if periodic (called from clearIntervalDet), false otherwise

Source:

(inner) clearTimeoutDet(cbId)

This function is to be binded to clearTimeout() function. It clears the timeout timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the callback indentifier of the one time delayed callback to clear.

Source:

(inner) clearTimeoutDet(cbId)

This function is to be binded to clearTimeout() function. It clears the timeout timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the callback indentifier of the one time delayed callback to clear.

Source:

(inner) clearTimeoutDet(cbId)

This function is to be binded to clearTimeout() function. It clears the timeout timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the callback indentifier of the one time delayed callback to clear.

Source:

(inner) computeNextSceduledTick()

Compute the next execution time to be scheduled. Since callbacks are sorted in callbackQueue in order of their next execution time, the next execution time of the one on then the top of the list is returned.

Source:
Returns:

the next execution time of the first callback in the sorted list

(inner) computeNextSceduledTick()

Compute the next execution time to be scheduled. Since callbacks are sorted in callbackQueue in order of their next execution time, the next execution time of the one on then the top of the list is returned.

Source:
Returns:

the next execution time of the first callback in the sorted list

(inner) computeNextSceduledTick()

Compute the next execution time to be scheduled. Since callbacks are sorted in callbackQueue in order of their next execution time, the next execution time of the one on then the top of the list is returned.

Source:
Returns:

the next execution time of the first callback in the sorted list

(inner) executeAndSetNextTick()

This function implements callbacks execution and update. It is called only by the host's setTimeout function. All delayed callbacks with next execution time less than the current time will be executing. Consequently, in case the system has accumulated some delay due, or example, to an over running program, all late callbacks will execute, but with respect to the order and atomicity set by the definitions. Next, the list is cleaned from no-more triggerable callbacks. And finally, the next tick is set.

Source:

(inner) executeAndSetNextTick()

This function implements callbacks execution and update. It is called only by the host's setTimeout function. All delayed callbacks with next execution time less than the current time will be executing. Consequently, in case the system has accumulated some delay due, or example, to an over running program, all late callbacks will execute, but with respect to the order and atomicity set by the definitions. Next, the list is cleaned from no-more triggerable callbacks. And finally, the next tick is set.

Source:

(inner) executeAndSetNextTick()

This function implements callbacks execution and update. It is called only by the host's setTimeout function. All delayed callbacks with next execution time less than the current time will be executing. Consequently, in case the system has accumulated some delay due, or example, to an over running program, all late callbacks will execute, but with respect to the order and atomicity set by the definitions. Next, the list is cleaned from no-more triggerable callbacks. And finally, the next tick is set.

Source:

(inner) executeCallbacks()

This function executes delayed callback such that their next execution time is equal to the nextScheduledTick. It then updates the next execution time if the callback is periodic, and remove it if not periodic. Labels are also deleted if the corresponding array is empty.

Source:

(inner) executeCallbacks()

This function executes delayed callback such that their next execution time is equal to the nextScheduledTick. It then updates the next execution time if the callback is periodic, and remove it if not periodic. Labels are also deleted if the corresponding array is empty.

Source:

(inner) executeCallbacks()

This function executes delayed callback such that their next execution time is equal to the nextScheduledTick. It then updates the next execution time if the callback is periodic, and remove it if not periodic. Labels are also deleted if the corresponding array is empty.

Source:

(inner) putInCallbackQueue(label, id)

callbackQueue variable keeps track of an ordered list of callbacks. This variable contains pointers to delayed callbacks, which are objects with two attributes: the label and the id.

This function performs a sorted insertion, given three levels of sorting. The first one is the 'nextExecutionTime'. Then, when two or more callbacks have the same nextExecutionTime, other levels of sorting are considered:

  • Second level of sorting: ascending order of labels (using the value of "origin")
  • Third level: within the same label, delayed callbacks are ordered by priorities first, then by an ascending order of the callback identifiers.
Parameters:
Name Type Description
label

the labeled clock domain of the delayedCallback to add

id

the unique id of of the delayedCallback to add

Source:

(inner) putInCallbackQueue(label, id)

callbackQueue variable keeps track of an ordered list of callbacks. This variable contains pointers to delayed callbacks, which are objects with two attributes: the label and the id.

This function performs a sorted insertion, given three levels of sorting. The first one is the 'nextExecutionTime'. Then, when two or more callbacks have the same nextExecutionTime, other levels of sorting are considered:

  • Second level of sorting: ascending order of labels (using the value of "origin")
  • Third level: within the same label, delayed callbacks are ordered by priorities first, then by an ascending order of the callback identifiers.
Parameters:
Name Type Description
label

the labeled clock domain of the delayedCallback to add

id

the unique id of of the delayedCallback to add

Source:

(inner) putInCallbackQueue(label, id)

callbackQueue variable keeps track of an ordered list of callbacks. This variable contains pointers to delayed callbacks, which are objects with two attributes: the label and the id.

This function performs a sorted insertion, given three levels of sorting. The first one is the 'nextExecutionTime'. Then, when two or more callbacks have the same nextExecutionTime, other levels of sorting are considered:

  • Second level of sorting: ascending order of labels (using the value of "origin")
  • Third level: within the same label, delayed callbacks are ordered by priorities first, then by an ascending order of the callback identifiers.
Parameters:
Name Type Description
label

the labeled clock domain of the delayedCallback to add

id

the unique id of of the delayedCallback to add

Source:

(inner) reset()

In case there are no more delayedCallbacks (that is when callbackQueue becomes empty or delayedCallbacks has no more callbacks, then reset all counter, identifiers, objects and lists.

Source:

(inner) reset()

In case there are no more delayedCallbacks (that is when callbackQueue becomes empty or delayedCallbacks has no more callbacks, then reset all counter, identifiers, objects and lists.

Source:

(inner) reset()

In case there are no more delayedCallbacks (that is when callbackQueue becomes empty or delayedCallbacks has no more callbacks, then reset all counter, identifiers, objects and lists.

Source:

(inner) setDelayedCallback(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

Both, setIntervalDet and setTimeoutDet create a new delayed callback, compute the next execution time, add it to delayedCallbacks and to callbackQueue, and possibly update
the next tick. The only difference if that the first one creates a new delayed callback such that periodic attribute is set to true, while the second creates one with periodic attribute set to false. The following function implements the core common behavior, while setting periodic to the value it should be. Therefore, setIntervalDet and setTimeoutDet just call this function with the right parameters.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback.

(inner) setDelayedCallback(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

Both, setIntervalDet and setTimeoutDet create a new delayed callback, compute the next execution time, add it to delayedCallbacks and to callbackQueue, and possibly update
the next tick. The only difference if that the first one creates a new delayed callback such that periodic attribute is set to true, while the second creates one with periodic attribute set to false. The following function implements the core common behavior, while setting periodic to the value it should be. Therefore, setIntervalDet and setTimeoutDet just call this function with the right parameters.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback.

(inner) setDelayedCallback(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

Both, setIntervalDet and setTimeoutDet create a new delayed callback, compute the next execution time, add it to delayedCallbacks and to callbackQueue, and possibly update
the next tick. The only difference if that the first one creates a new delayed callback such that periodic attribute is set to true, while the second creates one with periodic attribute set to false. The following function implements the core common behavior, while setting periodic to the value it should be. Therefore, setIntervalDet and setTimeoutDet just call this function with the right parameters.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback.

(inner) setIntervalDet(callback, timeout, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setInterval() function. It calls setDelayedCallback since the core function is the same as SetTimeoutDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback

(inner) setIntervalDet(callback, timeout, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setInterval() function. It calls setDelayedCallback since the core function is the same as SetTimeoutDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback

(inner) setIntervalDet(callback, timeout, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setInterval() function. It calls setDelayedCallback since the core function is the same as SetTimeoutDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback

(inner) setTimeoutDet(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setTimeout() function. It calls setDelayedCallback since the core function is the same as SetIntervalDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new one time delayed callback.

(inner) setTimeoutDet(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setTimeout() function. It calls setDelayedCallback since the core function is the same as SetIntervalDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new one time delayed callback.

(inner) setTimeoutDet(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setTimeout() function. It calls setDelayedCallback since the core function is the same as SetIntervalDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new one time delayed callback.

This is the implementation of another deterministic temporal semantics.

This module provides Accessors with deterministic temporal semantics, that are aligned with Cape Code's semantics. This module is to be explored by commonHost, so that any swarmlet host will enjoy these features. For this, accessors calls to setTimeout() or setInterval() are binded, respectively, to this module's setTioumetDet() and setIntervalDet(). It is guaranteed that only one timeout (function provided by the host) is pending
at any time and that callbacks will be executing with respect to their
logical clock domains and their relative priority and/or arrival time.

For this implementation, we assume that there is the physical time line, together with many logical time lines. All time lines do not advance the same way. Physical time is continuous and has the same rate, while logical time is updated at particular instances.

Each logical time line is associated with a 'labeled logical clock domains' (LLCD). This allows for defining and implementing logical simultaneity of callbacks execution.

The basic idea is to define each delayed callback with an LLCD. Two delayed callbacks with the same LLCD share the same logical time line. If they have the same logical time execution, then they will execute atomically one after another, such that their arrival order is respected. That is, if the instruction setInterval(F, T, 'A') was called before setInterval(G, T, 'A'), and no other action involving the LLCD 'A' has happened in between, then when F executes, it will be immediately followed by G.

When a call to the binded setTimeout or setInterval occurs, then scheduling the execution will depend on the LLCD. If it is a new one, then a new LLCD is created and its current logical time is set to the current physical time. However, if the LLCD is already defined, then the current logical time of that clock domain is used. In either cases, the callback will execute at its LLCD logical current time plus the timeout. Labeled logical clock domain are strings. However, if the programmer unintentionally or intentionally do not provide one, then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). The new anonymous clock domain is unique and is generated by incrementing defaultLabelIndex. An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

This implementation was preceded by a another one that adopts a slightly different semantics for the execution. In the previous version, any two callbacks with the same label execute starting from the same reference point in time. In addition, there are only two time lines: the physical one and the logical one. Therefore, delayed callbacks execute only with respect to the logical one. This way, the inter execution time is always respected. The drawback is that additional delays are added.

For the purpose of implementing temporal semantics, we record all delayed callBacks in the 'delayedCallbacks' object. This object is accessed by label. Within a labeled object, we record the current logical execution time, and the group of delayed callbacks having the same label. A new delayedCallback object is added to delayedCallbacks, given its label. In addition, each new object is uniquely identified by a number (generated by automatically incrementing cbIdentifier). Consequently, the identifier reflects the order in which the calls to setTimeout or setInterval occurred. This number is returned and is to be used for clearing the corresponding timer. This happens each time setTimeoutDet() or seIntervalDet() is called.

For the sake of any system that may need to define execution order based on predefined/precomputed priorities, it is possible to pass the priority as an argument to setTimeout or setInterval. Consequently, the third level of delayed callbacks ordering will be, first, based on priorities, then on arrival time (reflected by the identifiers). For the case of Accessors, the priority will be inherited from the accessor's priority (if defined).

In order to make the process fast, the list 'callbackQueue' keeps an incremental next execution time sorted list of pointers to the delayed callbacks. Pointers are objects with two attributes: the labeled clock domain and the identifier. This list, has three levels of sorting. The first one is obviously the execution time. If two or more callbacks have the same execution time, they are ordered by their labels origin. This is the second level of sorting. Finally, the third one is the callbacks ordering, reflected by the identifiers.

A delayed callback has the following attributes:

  • callbackFunction: the callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.
  • interval: The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.
  • periodic: if set to true, the callback needs to execute every interval time, otherwise, it executes only once. A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true).
  • nextExecutionTime: records the next time at which the callback should be executed.
  • priority is an optional attribute for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).
  • errorCallback is an optional attribute that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.
  • doneCallback is an optional attribute that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

    Proof: Done! Using Real-Time Maude :-)

Version:
  • $$Id: deterministicTemporalSemantics.js 2017-05-03 11:11:30Z chadlia.jerad $$
Author:
  • Chadlia Jerad and Edward A. Lee
Source:
Version:
  • $$Id: deterministicTemporalSemantics.js 2017-05-03 11:11:30Z chadlia.jerad $$
Author:
  • Chadlia Jerad and Edward A. Lee
Source:
Version:
  • $$Id: deterministicTemporalSemantics.js 2017-05-03 11:11:30Z chadlia.jerad $$
Author:
  • Chadlia Jerad and Edward A. Lee
Source:

Methods

(inner) clearIntervalDet(cbId)

This function is to be binded to clearInterval() function. It clears the periodic timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the cbIndentifier.

Source:

(inner) clearIntervalDet(cbId)

This function is to be binded to clearInterval() function. It clears the periodic timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the cbIndentifier.

Source:

(inner) clearIntervalDet(cbId)

This function is to be binded to clearInterval() function. It clears the periodic timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the cbIndentifier.

Source:

(inner) clearTick(cbId, periodic)

clearTick() parses delayedCallbacks in order to remove the one with the passed id and periodicity. It is also deleted from callbackQueue. If the first argument, that is the identifier, is not a number, than no need to parse.

Parameters:
Name Type Description
cbId

this parameter contains the callback identifier

periodic

boolean value: true if periodic (called from clearIntervalDet), false otherwise

Source:

(inner) clearTick(cbId, periodic)

clearTick() parses delayedCallbacks in order to remove the one with the passed id and periodicity. It is also deleted from callbackQueue. If the first argument, that is the identifier, is not a number, than no need to parse.

Parameters:
Name Type Description
cbId

this parameter contains the callback identifier

periodic

boolean value: true if periodic (called from clearIntervalDet), false otherwise

Source:

(inner) clearTick(cbId, periodic)

clearTick() parses delayedCallbacks in order to remove the one with the passed id and periodicity. It is also deleted from callbackQueue. If the first argument, that is the identifier, is not a number, than no need to parse.

Parameters:
Name Type Description
cbId

this parameter contains the callback identifier

periodic

boolean value: true if periodic (called from clearIntervalDet), false otherwise

Source:

(inner) clearTimeoutDet(cbId)

This function is to be binded to clearTimeout() function. It clears the timeout timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the callback indentifier of the one time delayed callback to clear.

Source:

(inner) clearTimeoutDet(cbId)

This function is to be binded to clearTimeout() function. It clears the timeout timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the callback indentifier of the one time delayed callback to clear.

Source:

(inner) clearTimeoutDet(cbId)

This function is to be binded to clearTimeout() function. It clears the timeout timer which identifier is given as parameter, by calling clearTick().

Parameters:
Name Type Description
cbId

this parameter is required. It is the callback indentifier of the one time delayed callback to clear.

Source:

(inner) computeNextSceduledTick()

Compute the next execution time to be scheduled. Since callbacks are sorted in callbackQueue in order of their next execution time, the next execution time of the one on then the top of the list is returned.

Source:
Returns:

the next execution time of the first callback in the sorted list

(inner) computeNextSceduledTick()

Compute the next execution time to be scheduled. Since callbacks are sorted in callbackQueue in order of their next execution time, the next execution time of the one on then the top of the list is returned.

Source:
Returns:

the next execution time of the first callback in the sorted list

(inner) computeNextSceduledTick()

Compute the next execution time to be scheduled. Since callbacks are sorted in callbackQueue in order of their next execution time, the next execution time of the one on then the top of the list is returned.

Source:
Returns:

the next execution time of the first callback in the sorted list

(inner) executeAndSetNextTick()

This function implements callbacks execution and update. It is called only by the host's setTimeout function. All delayed callbacks with next execution time less than the current time will be executing. Consequently, in case the system has accumulated some delay due, or example, to an over running program, all late callbacks will execute, but with respect to the order and atomicity set by the definitions. Next, the list is cleaned from no-more triggerable callbacks. And finally, the next tick is set.

Source:

(inner) executeAndSetNextTick()

This function implements callbacks execution and update. It is called only by the host's setTimeout function. All delayed callbacks with next execution time less than the current time will be executing. Consequently, in case the system has accumulated some delay due, or example, to an over running program, all late callbacks will execute, but with respect to the order and atomicity set by the definitions. Next, the list is cleaned from no-more triggerable callbacks. And finally, the next tick is set.

Source:

(inner) executeAndSetNextTick()

This function implements callbacks execution and update. It is called only by the host's setTimeout function. All delayed callbacks with next execution time less than the current time will be executing. Consequently, in case the system has accumulated some delay due, or example, to an over running program, all late callbacks will execute, but with respect to the order and atomicity set by the definitions. Next, the list is cleaned from no-more triggerable callbacks. And finally, the next tick is set.

Source:

(inner) executeCallbacks()

This function executes delayed callback such that their next execution time is equal to the nextScheduledTick. It then updates the next execution time if the callback is periodic, and remove it if not periodic. Labels are also deleted if the corresponding array is empty.

Source:

(inner) executeCallbacks()

This function executes delayed callback such that their next execution time is equal to the nextScheduledTick. It then updates the next execution time if the callback is periodic, and remove it if not periodic. Labels are also deleted if the corresponding array is empty.

Source:

(inner) executeCallbacks()

This function executes delayed callback such that their next execution time is equal to the nextScheduledTick. It then updates the next execution time if the callback is periodic, and remove it if not periodic. Labels are also deleted if the corresponding array is empty.

Source:

(inner) putInCallbackQueue(label, id)

callbackQueue variable keeps track of an ordered list of callbacks. This variable contains pointers to delayed callbacks, which are objects with two attributes: the label and the id.

This function performs a sorted insertion, given three levels of sorting. The first one is the 'nextExecutionTime'. Then, when two or more callbacks have the same nextExecutionTime, other levels of sorting are considered:

  • Second level of sorting: ascending order of labels (using the value of "origin")
  • Third level: within the same label, delayed callbacks are ordered by priorities first, then by an ascending order of the callback identifiers.
Parameters:
Name Type Description
label

the labeled clock domain of the delayedCallback to add

id

the unique id of of the delayedCallback to add

Source:

(inner) putInCallbackQueue(label, id)

callbackQueue variable keeps track of an ordered list of callbacks. This variable contains pointers to delayed callbacks, which are objects with two attributes: the label and the id.

This function performs a sorted insertion, given three levels of sorting. The first one is the 'nextExecutionTime'. Then, when two or more callbacks have the same nextExecutionTime, other levels of sorting are considered:

  • Second level of sorting: ascending order of labels (using the value of "origin")
  • Third level: within the same label, delayed callbacks are ordered by priorities first, then by an ascending order of the callback identifiers.
Parameters:
Name Type Description
label

the labeled clock domain of the delayedCallback to add

id

the unique id of of the delayedCallback to add

Source:

(inner) putInCallbackQueue(label, id)

callbackQueue variable keeps track of an ordered list of callbacks. This variable contains pointers to delayed callbacks, which are objects with two attributes: the label and the id.

This function performs a sorted insertion, given three levels of sorting. The first one is the 'nextExecutionTime'. Then, when two or more callbacks have the same nextExecutionTime, other levels of sorting are considered:

  • Second level of sorting: ascending order of labels (using the value of "origin")
  • Third level: within the same label, delayed callbacks are ordered by priorities first, then by an ascending order of the callback identifiers.
Parameters:
Name Type Description
label

the labeled clock domain of the delayedCallback to add

id

the unique id of of the delayedCallback to add

Source:

(inner) reset()

In case there are no more delayedCallbacks (that is when callbackQueue becomes empty or delayedCallbacks has no more callbacks, then reset all counter, identifiers, objects and lists.

Source:

(inner) reset()

In case there are no more delayedCallbacks (that is when callbackQueue becomes empty or delayedCallbacks has no more callbacks, then reset all counter, identifiers, objects and lists.

Source:

(inner) reset()

In case there are no more delayedCallbacks (that is when callbackQueue becomes empty or delayedCallbacks has no more callbacks, then reset all counter, identifiers, objects and lists.

Source:

(inner) setDelayedCallback(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

Both, setIntervalDet and setTimeoutDet create a new delayed callback, compute the next execution time, add it to delayedCallbacks and to callbackQueue, and possibly update
the next tick. The only difference if that the first one creates a new delayed callback such that periodic attribute is set to true, while the second creates one with periodic attribute set to false. The following function implements the core common behavior, while setting periodic to the value it should be. Therefore, setIntervalDet and setTimeoutDet just call this function with the right parameters.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback.

(inner) setDelayedCallback(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

Both, setIntervalDet and setTimeoutDet create a new delayed callback, compute the next execution time, add it to delayedCallbacks and to callbackQueue, and possibly update
the next tick. The only difference if that the first one creates a new delayed callback such that periodic attribute is set to true, while the second creates one with periodic attribute set to false. The following function implements the core common behavior, while setting periodic to the value it should be. Therefore, setIntervalDet and setTimeoutDet just call this function with the right parameters.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback.

(inner) setDelayedCallback(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

Both, setIntervalDet and setTimeoutDet create a new delayed callback, compute the next execution time, add it to delayedCallbacks and to callbackQueue, and possibly update
the next tick. The only difference if that the first one creates a new delayed callback such that periodic attribute is set to true, while the second creates one with periodic attribute set to false. The following function implements the core common behavior, while setting periodic to the value it should be. Therefore, setIntervalDet and setTimeoutDet just call this function with the right parameters.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback.

(inner) setIntervalDet(callback, timeout, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setInterval() function. It calls setDelayedCallback since the core function is the same as SetTimeoutDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback

(inner) setIntervalDet(callback, timeout, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setInterval() function. It calls setDelayedCallback since the core function is the same as SetTimeoutDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback

(inner) setIntervalDet(callback, timeout, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setInterval() function. It calls setDelayedCallback since the core function is the same as SetTimeoutDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new delayed callback

(inner) setTimeoutDet(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setTimeout() function. It calls setDelayedCallback since the core function is the same as SetIntervalDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new one time delayed callback.

(inner) setTimeoutDet(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setTimeout() function. It calls setDelayedCallback since the core function is the same as SetIntervalDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new one time delayed callback.

(inner) setTimeoutDet(callback, timeout, repeat, llcd, priority, errorCallback, doneCallback)

This function is to be binded to setTimeout() function. It calls setDelayedCallback since the core function is the same as SetIntervalDet. After the new delayedCallback is constructed, it is added to delayedCallbacks and to callbackQueue. If needed, the next tick is updated. The returned value is the unique id of the delayed callback.

Parameters:
Name Type Description
callback

The callback function, which will be invoked once or periodically, depending on the value of the repeat parameter.

timeout

The time until the first (or only) execution of the callback. This is a non-negative number interpreted as milliseconds (a negative number will be treated as zero). This is a logical time, relative to the current logical time of the llcd. If the llcd is null or has never before been created, then a new llcd will be created and its logical time will be set to (approximately) the current physical time.

repeat

A boolean specifying whether the callback should be invoked just once (with value false) or repeatedly, periodically, until stopped (with value true). To stop it, call clearTick(), passing the returned handle.

llcd

An optional argument giving the labeled logical clock domain label as a string. If no llcd argument is given (the argument is null or undefined), then a new anonymous clock domain is created with its logical time origin set to the current real time (approximately). An exception is that if llcd is not given and timeout is zero, then a single shared zero-delay clock domain is used. This exception is used to request an execution as soon as possible, before any callbacks in other clock domains are invoked. If there are multiple such zero-timeout anonymous llcd callbacks, then the order of their invocation will be determined by their priority, if one is given, and by the order of the request, if no priority is given or if a priority matches another priority.

priority

An optional argument for the priority over other delayed callbacks that use the same llcd and are scheduled to occur at the same logical time. This is either null or an integer, where a lower value means higher priority. If two priorities match, then the order of invocation matches the order in which requests are made (by calling this function).

errorCallback

An optional argument that provides a callback to execute in case the delayed callback's execution throws an error. If no callback is specified, then if the delayed callback throws an error, then the error message and stack trace will be printed to the console and execution will continue.

doneCallback

An optional argument that provides the callback to execute after the delayed callback has executed successfully. If repeat is true, then this callback will be invoked after each successful invocation of of the callback argument function.

Source:
Returns:

An integer that is the unique ID of the new one time delayed callback.