new Timer( [initValue])
Utility class to simplify use of timers created by setTimeout.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
initValue |
Object |
<optional> |
Specifies initial property values. Keys are property names, their values are values of corresponding properties. See setProperties for details. |
- Source:
- See:
Members
-
<protected> _action :module:chronoman~Action
-
Related action that should be executed after time period is elapsed.
Can be a function, an object havingexecutemethod or an object with fieldsfunc(function that will be executed) andcontext(thisfor 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 totrue.Type:
- Source:
- See:
-
<protected> _active :Boolean
-
Indicates whether timer is in use.
Type:
- Boolean
- Source:
- See:
-
<protected> _data :*
-
Auxiliary data associated with the timer instance.
Type:
- *
- Source:
-
_executeTime :Array.<Integer>
-
List that contain times when execute was called.
Type:
- Array.<Integer>
- Source:
- See:
-
<protected> _executionQty :Integer
-
Specifies how many times action was executed.
Type:
- Integer
- Source:
- See:
-
<protected> _passToAction :Boolean
-
Indicates whether the timer instance (
this) should be passed into action function when the function is called.Type:
- Boolean
- Source:
- See:
-
<protected> _period :module:chronoman~PeriodValue
-
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:
- Source:
- See:
-
<protected> _recurrent :Boolean
-
Indicates whether related action should be executed repeatedly.
Type:
- Boolean
- Source:
- See:
-
<protected> _repeatQty :Integer
-
Specifies how many times related action should be repeated after first execution.
Type:
- Integer
- Source:
- See:
-
<protected> _repeatTest :function
-
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
- Source:
- See:
-
<protected> _startTime :Integer|null
-
Time when timer was set active (was started).
Type:
- Integer | null
- Source:
- See:
-
<protected> _stopTime :Integer|null
-
Time when timer was set inactive (was stopped).
Type:
- Integer | null
- Source:
- See:
-
<protected> _timeoutId :Integer
-
Timer id.
Type:
- Integer
- Source:
- See:
-
actionResult :*
-
Result of action's last execution.
Type:
- *
- Source:
- See:
-
onExecute :function
-
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 totrue.Type:
- function
- Source:
- See:
-
onExecuteResult :*
-
Result of onExecute last execution.
Type:
- *
- Source:
- See:
Methods
-
<protected> _clearTimeout()
-
Cancel execution of scheduled action.
- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
<protected> _onTimeoutEnd()
-
Handle timeout's end.
- Source:
- See:
-
<protected> _setTimeout( [timeout])
-
Schedule related action execution.
Parameters:
Name Type Argument Description timeoutmodule: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.
- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
dispose()
-
Free resources that are allocated for object.
- Source:
-
execute()
-
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 totrue.
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);
- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
getAction()
-
Return value that represents action.
- Source:
- See:
Returns:
Function that represents action.
-
getData()
-
Return auxiliary data associated with the timer instance.
- Source:
- See:
Returns:
Auxiliary data associated with the timer instance.
- Type
- *
-
getExecuteTime()
-
Return list that contain times when execute was called.
- Source:
- See:
Returns:
List that contain times when execute was called.
- Type
- Array.<Integer>
-
getExecutionQty()
-
Return the value that indicates how many times action was executed.
- Source:
- See:
Returns:
Value that indicates how many times action was executed.
- Type
- Integer
-
getPeriod()
-
Return value determining time period that is used to schedule related action execution.
- Source:
- See:
Returns:
Value determining time period.
-
getPeriodValue( [value])
-
Return time period that will be used to schedule related action execution.
Parameters:
Name Type Argument Default Description valuemodule:chronoman~PeriodValue <optional>
this.getPeriod() Value that is used to calculation.
- Source:
- See:
Returns:
Time period in milliseconds.
- Type
- Integer
-
getRepeatQty()
-
Return the value that indicates how many times related action should be repeated after first execution.
- Source:
- See:
Returns:
Value that indicates how many times related action should be repeated after first execution.
- Type
- Integer
-
getRepeatTest()
-
Return the function that is used to determine whether action execution should be repeated.
- Source:
- See:
Returns:
Function that is used to determine whether action execution should be repeated.
- Type
- function
-
getStartTime()
-
Return time when timer was set active.
- Source:
- See:
Returns:
Time when timer was set active.
- Type
- Integer | null
-
getStopTime()
-
Return time when timer was set inactive.
- Source:
- See:
Returns:
Time when timer was set inactive.
- Type
- Integer | null
-
isActive()
-
Test whether timer is in use.
- Source:
- See:
Returns:
true, if timer is in use, otherwisefalse.- Type
- Boolean
-
isPassToAction()
-
Test whether the timer instance should be passed into action function when the function is called.
- Source:
- See:
Returns:
true, if the timer instance should be passed, otherwisefalse.- Type
- Boolean
-
isRecurrent()
-
Test whether related action should be executed repeatedly.
- Source:
- See:
Returns:
true, if related action should be executed repeatedly, otherwisefalse.- Type
- Boolean
-
setAction(action)
-
Set value which represents action that should be executed after time period is elapsed.
Parameters:
Name Type Description actionmodule:chronoman~Action Value that represents action.
- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
setActive(bActive)
-
Set or cancel timer usage. Depending of this schedules related action execution or cancels action execution.
Consecutive calling withbActive = trueleads to related action execution delaying.Parameters:
Name Type Description bActiveBoolean trueto schedule related action execution,falseto cancel action execution.- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
setData(data)
-
Set auxiliary data associated with the timer instance.
Parameters:
Name Type Description data* Auxiliary data associated with the timer instance.
- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
setExecutionQty(nQty)
-
Set the value that indicates how many times action was executed.
Parameters:
Name Type Description nQtyInteger Value that indicates how many times action was executed.
- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
setPassToAction(bPass)
-
Set or cancel passing of timer instance into action function.
Parameters:
Name Type Description bPassBoolean true, if the timer instance should be passed into action function,false, if the instance should not be passed.- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
setPeriod(period)
-
Set value determining time period that is used to schedule related action execution.
Parameters:
Name Type Description periodmodule:chronoman~PeriodValue Value determining time period.
- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
setProperties(propMap)
-
Set timer properties.
Parameters:
Name Type Description propMapObject Specifies property values. Keys are property names, their values are values of corresponding properties. The following keys (properties) can be specified:
Name Type Description action Function Related action that should be executed after time period is elapsed. active Boolean Whether timer usage should be immediately started. data Any Auxiliary data associated with the timer instance. passToAction Boolean Whether the timer instance should be passed into action function when the function is called. period module:chronoman~PeriodValue Value determining time period in milliseconds that is used to schedule related action execution. recurrent Boolean Whether related action should be executed repeatedly. repeatQty Integer How many times related action should be repeated after first execution. repeatTest Function Function that should be used to determine whether action execution should be repeated. - Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
setRecurrent(bRecurrent)
-
Set or cancel repeating of related action execution.
Parameters:
Name Type Description bRecurrentBoolean true, if action should be executed repeatedly,false, if action repeating should be off.- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
setRepeatQty(nQty)
-
Set how many times related action should be repeated after first execution.
Parameters:
Name Type Description nQtyInteger Value that indicates how many times related action should be repeated after first execution.
- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
setRepeatTest(test)
-
Set the function that should be used to determine whether action execution should be repeated.
Parameters:
Name Type Description testfunction Function that should be used to determine whether action execution should be repeated.
- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
start( [property])
-
Start timer usage (make it active).
Parameters:
Name Type Argument Description propertymodule: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.
- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
stop()
-
Stop timer usage (make it inactive).
- Source:
- See:
Returns:
Reference to
thisobject.- Type
- Object
-
toString()
-
Convert object into string.
- Source: