Functions
Threading APIs consist of the following functions, which are a part of the kony Namespace.
This API helps you run the JavaScript code on the main thread. It is an asynchronous API. It posts a message to the main thread to invoke a function f with parameters arguments.
NOTE: If runonMainThread is invoked in a JavaScript function that is already running on the main thread, then the function is executed in synchronous mode.
Syntax
kony.runOnMainThread (f, args);
Input Parameters
Parameters | Description |
---|---|
f [Function] - Mandatory | Specifies the callback function that must be executed. |
args [Array] - Mandatory | Specifies the JavaScript array that holds the parameters to be passed to function f. |
Example
kony.runOnMainThread(mainthread, []); function mainthread () { kony.print ("Running on On Main Thread"); }
Return Values
None
Platform Availability
- Android
- iOS
Provides apps with multithreading capabilities.
Syntax
kony.runOnWorkerThread(f,args);
Input Parameters
Parameters | Description |
---|---|
f | Specifies the callback function that must be executed. |
args | Specifies an array that holds the parameters to be passed to the function indicated by the f parameter. |
Example
kony.runOnWorkerThread(workermethod, []); function workermethod () { kony.print ("Running on On Worker Thread"); }
Return Values
None.
Remarks
This function helps you run JavaScript code asynchronously on a worker thread. It posts a message to the worker thread that owns the current JavaScript context to invoke the function specified in the f parameter.
IMPORTANT: The assumption here is that main thread does not own any JavaScript context. The VM/closure thread and worker threads own the JavaScript context. When the kony.runOnWorkerThread is invoked from the main thread, a message is posted to the thread that originally invoked the kony.runOnMainThread. If the runonWorkerThread is invoked in a JavaScript function that is already running on the worker thread, then the function would be executed in synchronous mode.
Platform Availability
- Android
- iOS