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 :function

Related action that should be executed after time period is elapsed.
The timer instance to which the action is associated will be passed as function's parameter if passToAction property is set to true.

Type:
  • function
Source:
See:

<protected> _active :Boolean

Indicates whether timer is in use.

Type:
  • Boolean
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 :Integer

Time period in milliseconds. A related action will be executed when the period is elapsed.

Type:
  • Integer
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 first action execution to determine whether execution should be repeated. If the function returns a true value it means that execution will be repeated.
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()

Schedule related action execution.

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

Reference to this object.

Type
Object

getAction()

Return function that represents action.

Source:
See:
Returns:

Function that represents action.

Type
function

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 time period that is 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 function which represents action that should be executed after time period is elapsed.

Parameters:
Name Type Description
action function

Function 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

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(nPeriod)

Set time period that is used to schedule related action execution.

Parameters:
Name Type Description
nPeriod Integer

Time period in milliseconds.

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.
passToAction Boolean Whether the timer instance should be passed into action function when the function is called.
period Integer 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 Integer | 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: