Class: Timer

chronoman~ Timer


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 or an object having execute method.
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:
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:

<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, array of periods or function that returns period or array of periods. A related action will be executed when the period is elapsed.
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 this number will be used as time period in milliseconds to schedule next action execution.
The timer instance to which the test is associated will be passed as function's parameter.

Type:
  • function
Source:
See:

<protected> _timeoutId :Integer

Timer id.

Type:
  • Integer
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 to true.

Type:
  • function
Source:
See:

Methods


<protected> _clearTimeout()

Cancel execution of scheduled action.

Source:
See:
Returns:

Reference to this object.

Type
Object

<protected> _onTimeoutEnd()

Handle timeout's end.

Source:
See:

<protected> _setTimeout( [nTimeout])

Schedule related action execution.

Parameters:
Name Type Argument Description
nTimeout Integer <optional>

Time period in milliseconds 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 this object.

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 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);
Source:
See:
Returns:

Reference to this object.

Type
Object

getAction()

Return value that represents action.

Source:
See:
Returns:

Function that represents action.

Type
module:chronoman~Action

getData()

Return auxiliary data associated with the timer instance.

Source:
See:
Returns:

Auxiliary data associated with the timer instance.

Type
*

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.

Type
module:chronoman~PeriodValue

getPeriodValue()

Return time period that will be used to schedule related action execution.

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

isActive()

Test whether timer is in use.

Source:
See:
Returns:

true, if timer is in use, otherwise false.

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, otherwise false.

Type
Boolean

isRecurrent()

Test whether related action should be executed repeatedly.

Source:
See:
Returns:

true, if related action should be executed repeatedly, otherwise false.

Type
Boolean

setAction(action)

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.

Source:
See:
Returns:

Reference to this object.

Type
Object

setActive(bActive)

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

true to schedule related action execution, false to cancel action execution.

Source:
See:
Returns:

Reference to this object.

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 this object.

Type
Object

setPassToAction(bPass)

Set or cancel passing of timer instance into action function.

Parameters:
Name Type Description
bPass Boolean

true, if the timer instance should be passed into action function, false, if the instance should not be passed.

Source:
See:
Returns:

Reference to this object.

Type
Object

setPeriod(period)

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.

Source:
See:
Returns:

Reference to this object.

Type
Object

setProperties(propMap)

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:

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 this object.

Type
Object

setRecurrent(bRecurrent)

Set or cancel repeating of related action execution.

Parameters:
Name Type Description
bRecurrent Boolean

true, if action should be executed repeatedly, false, if action repeating should be off.

Source:
See:
Returns:

Reference to this object.

Type
Object

setRepeatQty(nQty)

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.

Source:
See:
Returns:

Reference to this object.

Type
Object

setRepeatTest(test)

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.

Source:
See:
Returns:

Reference to this object.

Type
Object

start( [property])

Start timer usage (make it active).

Parameters:
Name Type Argument 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.

Source:
See:
Returns:

Reference to this object.

Type
Object

stop()

Stop timer usage (make it inactive).

Source:
See:
Returns:

Reference to this object.

Type
Object

toString()

Convert object into string.

Source: