new Timer(initValueopt)
- Source:
- See:
Utility class to simplify use of timers created by setTimeout.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
initValue |
Object |
<optional> |
Specifies initial property values. Keys are property names, their values are values of corresponding properties. See setProperties for details. |
Members
(protected) _action :module:chronoman~Action
- Source:
- See:
Related action that should be executed after time period is elapsed.
Can be a function, an object having execute
method
or an object with fields func
(function that will be executed)
and context
(this
for function's call).
The timer instance to which the action is associated will be passed as function's/method's parameter
if passToAction property is set to true
.
Type:
(protected) _active :Boolean
- Source:
- See:
Indicates whether timer is in use.
Type:
- Boolean
(protected) _data :*
- Source:
Auxiliary data associated with the timer instance.
Type:
- *
_executeTime :Array.<Integer>
- Source:
- See:
List that contain times when execute was called.
Type:
- Array.<Integer>
(protected) _executionQty :Integer
- Source:
- See:
Specifies how many times action was executed.
Type:
- Integer
(protected) _passToAction :Boolean
- Source:
- See:
Indicates whether the timer instance (this
) should be passed into action function when the function is called.
Type:
- Boolean
(protected) _period :module:chronoman~PeriodValue
- Source:
- See:
Time period in milliseconds, object specifying random time period, array of periods
or function that returns period or array of periods.
A related action will be executed when the period is elapsed.
When an object is set the used period is selected randomly.
The object can have the following properties:
list
- a non-empty array of integer numbers from which the period will be selected randomly.start
- an integer number representing minimal point of interval from which random time period should be generated; default value - 0.end
- an integer number representing maximal point of interval from which random time period should be generated; default value -start + 1000
.
When array of periods is set the used period is selected in the following way: first array item (with index 0) specifies period before first action's execution, second array item (with index 1) specifies period before second action's execution, and so on. When quantity of action executions is more than array's length the last item of array is used as period for subsequent executions.
When function is set its returned value is used to determine next period. The timer instance to which the function is associated will be passed as function's parameter. When function returns an array of periods the array is used to select period before next execution according to rules described above.
Type:
(protected) _recurrent :Boolean
- Source:
- See:
Indicates whether related action should be executed repeatedly.
Type:
- Boolean
(protected) _repeatQty :Integer
- Source:
- See:
Specifies how many times related action should be repeated after first execution.
Type:
- Integer
(protected) _repeatTest :function
- Source:
- See:
Specifies function that should be called after action execution to determine
whether execution should be repeated.
If the function returns a true value or non-negative number it means that execution will be repeated.
When the function returns non-negative number, array, object or function this value will be used
to calculate time period in milliseconds to schedule next action execution
(see getPeriodValue).
The timer instance to which the test is associated will be passed as function's parameter.
Type:
- function
(protected) _startTime :Integer|null
- Source:
- See:
Time when timer was set active (was started).
Type:
- Integer | null
(protected) _stopTime :Integer|null
- Source:
- See:
Time when timer was set inactive (was stopped).
Type:
- Integer | null
(protected) _timeoutId :Integer
- Source:
- See:
Timer id.
Type:
- Integer
actionResult :*
- Source:
- See:
Result of action's last execution.
Type:
- *
onExecute :function
- Source:
- See:
Function that should be executed after time period is elapsed.
The timer instance to which the function is associated will be passed as function's parameter
if passToAction property is set to true
.
Type:
- function
onExecuteResult :*
- Source:
- See:
Result of onExecute last execution.
Type:
- *
Methods
(protected) _clearTimeout() → {Object}
- Source:
- See:
Cancel execution of scheduled action.
Returns:
Reference to this
object.
- Type
- Object
(protected) _onTimeoutEnd()
- Source:
- See:
Handle timeout's end.
(protected) _setTimeout(timeoutopt) → {Object}
- Source:
- See:
Schedule related action execution.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
timeout |
module:chronoman~PeriodValue |
<optional> |
Time period that is used to schedule action execution. By default the current value of period property is used to determine time period. |
Returns:
Reference to this
object.
- Type
- Object
dispose()
- Source:
Free resources that are allocated for object.
execute() → {Object}
- Source:
- See:
Execute related action (function).
The timer instance to which the action is associated will be passed as function's parameter
if passToAction property is set to true
.
Action's next execution will be scheduled when one of the following conditions is true:
- timer is set as recurrent (see isRecurrent);
- specified quantity of repeats is not reached (see getRepeatQty);
- specified repeat test is passed i.e. the test function returns true value or non-negative number (see getRepeatTest);
Returns:
Reference to this
object.
- Type
- Object
getAction() → {module:chronoman~Action}
- Source:
- See:
Return value that represents action.
Returns:
Function that represents action.
getData() → {*}
- Source:
- See:
Return auxiliary data associated with the timer instance.
Returns:
Auxiliary data associated with the timer instance.
- Type
- *
getExecuteTime() → {Array.<Integer>}
- Source:
- See:
Return list that contain times when execute was called.
Returns:
List that contain times when execute was called.
- Type
- Array.<Integer>
getExecutionQty() → {Integer}
- Source:
- See:
Return the value that indicates how many times action was executed.
Returns:
Value that indicates how many times action was executed.
- Type
- Integer
getPeriod() → {module:chronoman~PeriodValue}
- Source:
- See:
Return value determining time period that is used to schedule related action execution.
Returns:
Value determining time period.
getPeriodValue(valueopt) → {Integer}
- Source:
- See:
Return time period that will be used to schedule related action execution.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
module:chronoman~PeriodValue |
<optional> |
this.getPeriod()
|
Value that is used to calculation. |
Returns:
Time period in milliseconds.
- Type
- Integer
getRepeatQty() → {Integer}
- Source:
- See:
Return the value that indicates how many times related action should be repeated after first execution.
Returns:
Value that indicates how many times related action should be repeated after first execution.
- Type
- Integer
getRepeatTest() → {function}
- Source:
- See:
Return the function that is used to determine whether action execution should be repeated.
Returns:
Function that is used to determine whether action execution should be repeated.
- Type
- function
getStartTime() → {Integer|null}
- Source:
- See:
Return time when timer was set active.
Returns:
Time when timer was set active.
- Type
- Integer | null
getStopTime() → {Integer|null}
- Source:
- See:
Return time when timer was set inactive.
Returns:
Time when timer was set inactive.
- Type
- Integer | null
isActive() → {Boolean}
- Source:
- See:
Test whether timer is in use.
Returns:
true
, if timer is in use, otherwise false
.
- Type
- Boolean
isPassToAction() → {Boolean}
- Source:
- See:
Test whether the timer instance should be passed into action function when the function is called.
Returns:
true
, if the timer instance should be passed, otherwise false
.
- Type
- Boolean
isRecurrent() → {Boolean}
- Source:
- See:
Test whether related action should be executed repeatedly.
Returns:
true
, if related action should be executed repeatedly, otherwise false
.
- Type
- Boolean
setAction(action) → {Object}
- Source:
- See:
Set value which represents action that should be executed after time period is elapsed.
Parameters:
Name | Type | Description |
---|---|---|
action |
module:chronoman~Action | Value that represents action. |
Returns:
Reference to this
object.
- Type
- Object
setActive(bActive) → {Object}
- Source:
- See:
Set or cancel timer usage.
Depending of this schedules related action execution or cancels action execution.
Consecutive calling with bActive = true
leads to related action execution delaying.
Parameters:
Name | Type | Description |
---|---|---|
bActive |
Boolean |
|
Returns:
Reference to this
object.
- Type
- Object
setData(data) → {Object}
- Source:
- See:
Set auxiliary data associated with the timer instance.
Parameters:
Name | Type | Description |
---|---|---|
data |
* | Auxiliary data associated with the timer instance. |
Returns:
Reference to this
object.
- Type
- Object
setExecutionQty(nQty) → {Object}
- Source:
- See:
Set the value that indicates how many times action was executed.
Parameters:
Name | Type | Description |
---|---|---|
nQty |
Integer | Value that indicates how many times action was executed. |
Returns:
Reference to this
object.
- Type
- Object
setPassToAction(bPass) → {Object}
- Source:
- See:
Set or cancel passing of timer instance into action function.
Parameters:
Name | Type | Description |
---|---|---|
bPass |
Boolean |
|
Returns:
Reference to this
object.
- Type
- Object
setPeriod(period) → {Object}
- Source:
- See:
Set value determining time period that is used to schedule related action execution.
Parameters:
Name | Type | Description |
---|---|---|
period |
module:chronoman~PeriodValue | Value determining time period. |
Returns:
Reference to this
object.
- Type
- Object
setProperties(propMap) → {Object}
- Source:
- See:
Set timer properties.
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
propMap |
Object | Specifies property values. Keys are property names, their values are values of corresponding properties. The following keys (properties) can be specified:
|
Returns:
Reference to this
object.
- Type
- Object
setRecurrent(bRecurrent) → {Object}
- Source:
- See:
Set or cancel repeating of related action execution.
Parameters:
Name | Type | Description |
---|---|---|
bRecurrent |
Boolean |
|
Returns:
Reference to this
object.
- Type
- Object
setRepeatQty(nQty) → {Object}
- Source:
- See:
Set how many times related action should be repeated after first execution.
Parameters:
Name | Type | Description |
---|---|---|
nQty |
Integer | Value that indicates how many times related action should be repeated after first execution. |
Returns:
Reference to this
object.
- Type
- Object
setRepeatTest(test) → {Object}
- Source:
- See:
Set the function that should be used to determine whether action execution should be repeated.
Parameters:
Name | Type | Description |
---|---|---|
test |
function | Function that should be used to determine whether action execution should be repeated. |
Returns:
Reference to this
object.
- Type
- Object
start(propertyopt) → {Object}
- Source:
- See:
Start timer usage (make it active).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
property |
module:chronoman~PeriodValue | Object |
<optional> |
Time period in milliseconds that is used to schedule related action execution (new value for period property) or object that specifies new values for timer properties (see setProperties). The current value of period property is used by default. |
Returns:
Reference to this
object.
- Type
- Object
stop() → {Object}
- Source:
- See:
Stop timer usage (make it inactive).
Returns:
Reference to this
object.
- Type
- Object
toString()
- Source:
Convert object into string.