AbstractTimerManager
On this page
- AbstractTimerManager ⇐
Class
- AbstractTimerManager()
- decorateBuildinMethods()
- define(timerId, handler, delay) ⇒
Object
- start(timerId, optionalCallbackContext, param) ⇒
Boolean
- startImmediately(timerId, optionalCallbackContext, param) ⇒
Boolean
- stop(timerId) ⇒
Boolean
- restart(timerId, optionalCallbackContext) ⇒
Boolean
- isStarted(timerId) ⇒
Boolean
- status(timerId) ⇒
Object
- changeDelay(timerId, newDelay) ⇒
Object
- setTimeout(handler, delay, timerId, optionalCallbackContext, param) ⇒
String
|null
- clearTimeout(timerId) ⇒
Boolean
- setInterval(handler, delay, timerId) ⇒
String
|null
- clearInterval(timerId) ⇒
Boolean
AbstractTimerManager ⇐ Class
Kind: global abstract class
Extends: Class
Manager:
Properties
Name | Type | Description |
---|---|---|
overrideDelays | Object | 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 ⇐
Class
- new AbstractTimerManager()
- .decorateBuildinMethods()
- .define(timerId, handler, delay) ⇒
Object
- .start(timerId, optionalCallbackContext, param) ⇒
Boolean
- .startImmediately(timerId, optionalCallbackContext, param) ⇒
Boolean
- .stop(timerId) ⇒
Boolean
- .restart(timerId, optionalCallbackContext) ⇒
Boolean
- .isStarted(timerId) ⇒
Boolean
- .status(timerId) ⇒
Object
- .changeDelay(timerId, newDelay) ⇒
Object
- .setTimeout(handler, delay, timerId, optionalCallbackContext, param) ⇒
String
|null
- .clearTimeout(timerId) ⇒
Boolean
- .setInterval(handler, delay, timerId) ⇒
String
|null
- .clearInterval(timerId) ⇒
Boolean
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
Param | Type | Description |
---|---|---|
timerId | String | The id the timer will be referenced by |
handler | function | The handler called when time is up |
delay | number | 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
Param | Type | Description |
---|---|---|
timerId | String | The id of the timer |
optionalCallbackContext | Object | 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
Param | Type | Description |
---|---|---|
timerId | String | The id of the timer |
optionalCallbackContext | Object | 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
Param | Type | Description |
---|---|---|
timerId | String | The id of the timer |
restart(timerId, optionalCallbackContext) ⇒ Boolean
Restart a timer
Kind: instance method of AbstractTimerManager
Returns: Boolean
- True if successfully restarted
Param | Type | Description |
---|---|---|
timerId | String | The id of the timer |
optionalCallbackContext | Object | 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
Param | Type | Description |
---|---|---|
timerId | String | 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
Param | Type | Description |
---|---|---|
timerId | String | 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
Param | Type | Description |
---|---|---|
timerId | String | The id of the timer |
newDelay | number | 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
Param | Type | Description |
---|---|---|
handler | function | The handler called when time is up |
delay | number | Time in milliseconds the timer last |
timerId | String | An optional timer id |
optionalCallbackContext | Object | 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
Param | Type | Description |
---|---|---|
timerId | String | 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
Param | Type | Description |
---|---|---|
handler | function | The handler called when time is up |
delay | number | Time in milliseconds the timer last |
timerId | String | 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
Param | Type | Description |
---|---|---|
timerId | String | The id the interval will be referenced by |