AbstractTimerManager

AbstractTimerManager ⇐ Class

Kind: global abstract class
Extends: Class
Manager:
Properties

NameTypeDescription
overrideDelaysObject

a key-value map where the key is the id of the timer and the value it's delay / it is prioritary over the delay used to create the timer usefull to override the delay of timer(s) by configuration (tests, ...)

AbstractTimerManager()

This class let you manage timers used throughout the application.

Example

$TimerManager.getInstance().define("my5secondsTimer", function() {console.log("my5secondsTimer cb");}, 5000)
     .start("my5secondsTimer");
# or in a more javascript fashion
$TimerManager.getInstance().setTimeout(function() {console.log("my5secondsTimer cb");}, 5000, "my5secondsTimer");
console.log("remaining:"+$TimerManager.getInstance().status("my5secondsTimer").remaining+" ms");
$TimerManager.getInstance().restart("my5secondsTimer");
$TimerManager.getInstance().stop("my5secondsTimer");

decorateBuildinMethods()

Decorate the buildin methods setTimeout and clearTimeout with the one defined by the manager

Kind: instance method of AbstractTimerManager

define(timerId, handler, delay) ⇒ Object

Define a new timer, that can be used throughout the application

Kind: instance method of AbstractTimerManager
Returns: Object - The manager instance

ParamTypeDescription
timerIdString

The id the timer will be referenced by

handlerfunction

The handler called when time is up

delaynumber

Time in milliseconds the timer last

start(timerId, optionalCallbackContext, param) ⇒ Boolean

Start a timeout previously defined

Kind: instance method of AbstractTimerManager
Returns: Boolean - True if successfully started

ParamTypeDescription
timerIdString

The id of the timer

optionalCallbackContextObject

The context ('this') that will be used inside the callback

param*

A param for the handler

startImmediately(timerId, optionalCallbackContext, param) ⇒ Boolean

Start a timeout previously defined immediately, ie with no timeout. The handler is called immediately (ie not deferred into a setTimeout with a 0 sec delay)

Kind: instance method of AbstractTimerManager
Returns: Boolean - True if successfully started

ParamTypeDescription
timerIdString

The id of the timer

optionalCallbackContextObject

The context ('this') that will be used inside the callback

param*

A param for the handler

stop(timerId) ⇒ Boolean

Stop a timeout previously started

Kind: instance method of AbstractTimerManager
Returns: Boolean - True if successfully stopped

ParamTypeDescription
timerIdString

The id of the timer

restart(timerId, optionalCallbackContext) ⇒ Boolean

Restart a timer

Kind: instance method of AbstractTimerManager
Returns: Boolean - True if successfully restarted

ParamTypeDescription
timerIdString

The id of the timer

optionalCallbackContextObject

The context ('this') that will be used inside the callback

isStarted(timerId) ⇒ Boolean

Return true if the timer is started

Kind: instance method of AbstractTimerManager
Returns: Boolean - True if the timer is started

ParamTypeDescription
timerIdString

The id of the timer

status(timerId) ⇒ Object

Return the status of the timer

Kind: instance method of AbstractTimerManager
Returns: Object - status The timer status

  • timerId The timer id or null if the requested timer does not exists
  • isStarted True if the timer is started
  • remaining Time in milliseconds before timer callback is called; 0 if timer is not started
ParamTypeDescription
timerIdString

The id of the timer

changeDelay(timerId, newDelay) ⇒ Object

Change the delay of an existing timer

Kind: instance method of AbstractTimerManager
Returns: Object - The manager instance

ParamTypeDescription
timerIdString

The id of the timer

newDelaynumber

Time in milliseconds the timer last

setTimeout(handler, delay, timerId, optionalCallbackContext, param) ⇒ String | null

Declare a new timer It is the equivalent of the Javascript function, except you can only specify a function as the first args (and not a string code to be evaluated) You can also assign a ‘readable’ identifier (useful for debug and for managing created timer)

Kind: instance method of AbstractTimerManager
Returns: String | null - The timer id or null in case of problem

ParamTypeDescription
handlerfunction

The handler called when time is up

delaynumber

Time in milliseconds the timer last

timerIdString

An optional timer id

optionalCallbackContextObject

The context ('this') that will be used inside the callback

param*

A param for the handler

clearTimeout(timerId) ⇒ Boolean

Clear a timer. It is the equivalent of the Javascript function, except you can use the ‘readable’ identifier

Kind: instance method of AbstractTimerManager
Returns: Boolean - True if timer has been clear

ParamTypeDescription
timerIdString

The id the timer will be referenced by

setInterval(handler, delay, timerId) ⇒ String | null

Declare a new timer It is the equivalent of the Javascript function, except you can only specify a function as the first args (and not a string code to be evaluated) You can also assign a ‘readable’ identifier (useful for debug and for managing created timer)

Kind: instance method of AbstractTimerManager
Returns: String | null - The timer id or null in case of problem

ParamTypeDescription
handlerfunction

The handler called when time is up

delaynumber

Time in milliseconds the timer last

timerIdString

An optional timer id

clearInterval(timerId) ⇒ Boolean

Clear an interval. It is the equivalent of the Javascript function, except you can use the ‘readable’ identifier

Kind: instance method of AbstractTimerManager
Returns: Boolean - True if interval has been clear

ParamTypeDescription
timerIdString

The id the interval will be referenced by