kony.timer Namespace
The kony.timer namespace implements the Timer API. It contains the following API elements.
Functions
The kony.timer namepace provides the following functions.
This API cancels the timer that has already been scheduled for execution.
Syntax
kony.timer.cancel(timerid);
Input Parameters
Parameter | Description |
---|---|
timerid [String] - Mandatory | Specifies the unique ID that identifies the timer that needs to be canceled. |
Example
/*To cancel the scheduled timer use the below code snipppet. Use the Timer ID of the scheduled timer to cancel the timer. */ cancelTimer: function(){ kony.timer.cancel("timer4"); alert("You have successfully cancelled the timer"); }
Return Values
None
Exceptions
Error
Error Codes
- 100 - invalid arguments
- 101 - internal error
Implementation Details
If the timer is waiting to be run, it will not be run the next time. If the timer is in the middle of execution, it will be allowed to complete and then canceled.
Platform Availability
Available on all platforms.
This API specifies the callback function that needs to be executed for a scheduled timer. The callback function handles the logic that needs to be executed after a scheduled timer was run successfully or the scheduled timer failed to execute. The setCallBack timer API is provided to override the existing time call back function which is defined in the "schedule" timer API.
Syntax
kony.timer.setCallBack(timerid, callbackfunction);
Input Parameters
Parameter | Description |
---|---|
timerid [String] - Mandatory | Specifies the unique ID that identifies the timer. |
callbackfunction [Function] - Mandatory | Specifies the callback function that needs to be executed. |
Example
//This function is called when you use the setCallBack Timer API callbackfunction: function(){ alert("Hello World"); }, //To set a callback function for a scheduled timer, use the below code snippet. setCallBackTimer: function(){ kony.timer.setCallBack("timer4", this.callbackfunction); },
Return Values
None
Exceptions
Error
Platform Availability
Available on all platforms.
This API executes the given function after a specified interval of time.
Use Cases
You can use this API when you want to execute a function after a specified interval of time. i.e, for example to run a specific function for every 15 seconds.
Syntax
kony.timer.schedule(timerid, functionObj, interval, repeat) ;
Input Parameters
Parameter | Description |
---|---|
timerid [String] - Mandatory | Specifies the unique ID that identifies the timer. |
functionObj [Function] - Mandatory | Specifies the function that needs to be executed. |
interval [Number] - Mandatory | Specifies the time in seconds after which the function needs to be executed. |
repeat [Boolean] - Mandatory | Specifies a flag that indicates if the function needs to executed once or repeated.
|
Example
//This function is called when you schedule the timer generateAlert: function(){ alert("You have generated an alert after 3 seconds "); }, //To schedule a timer to display an alert after 3 seconds use the below snippet. scheduleTimer: function(){ kony.timer.schedule("timer4",this.generateAlert, 3, true); },
Return Values
None
Exceptions
Error
Platform Availability
Available on all platforms.