kony.worker Namespace
The kony.worker namespace implements the Worker Thread API. It contains the following API elements.
Functions
The kony.worker namespace provides the following functions.
This API is used during runtime only in parent scope to determine whether the current platform environment has worker thread support.
This API is most useful in case of Desktop Web platform where runtime query can be made to determine whether a browser environment supports Worker Threads or not.
Syntax
kony.worker.hasWorkerThreadSupport();
Input Parameters
None
Example
var hasWorkerSupport = kony.worker.hasWorkerThreadSupport(); if (hasWorkerSupport) { var worker = new kony.worker.WorkerThread("worker1.js"); //do something } else { //workers not supported }
Return Values
Return Value | Description |
---|---|
Boolean |
true: When worker thread support is present. false: When worker thread support is not present. |
Platform Availability
- iOS
- Android
- Desktop Web
For more information, see Scope.
The kony.worker.WorkerThread function creates a WorkerThread object and returns a handle to it. The worker object represents a worker thread.
Syntax
kony.worker.WorkerThread(workerjs);
Input Parameters
Parameter | Description |
---|---|
workerjs | A string that contains either the name of javascript file name or functional module name which contains worker thread code. |
Example
try { var worker = new kony.worker.WorkerThread("worker1.js"); } catch (e) { var err = kony.getError(e); if (err instanceof KonyError) { kony.print("KonyError Catch : " + JSON.stringify(err)); } }
Return Values
Returns a WorkerThread
object.
Exceptions
Error Code | Name | Message | Reason |
---|---|---|---|
3001 | WorkerThreadError | WorkerThread: MissingMandatoryParameter. Failed to construct WorkerThread | If no argument is given to this function, this exception is thrown and workerThread object is not created. |
3002 | WorkerThreadError | WorkerThread: InvalidParameter. Invalid script name | If the workerjs argument is not a string, then this exception is thrown and workerThread object is not created. |
- If the script or module specified by the
workerjs
argument is not found, and if an error event handler is registered for thisWorkerThread
object in the parent scope, then the error event handler is invoked with an error object and itsmessage
attribute set to following.message:"WorkerThread: InvalidParameter. WorkerThread script not found"
- In this error scenario no ‘KonyError’ exception will be raised.
- Also the
filename
,lineno
properties in the error event object for this error scenario have undefined values.
- If multiple arguments are provided separated by a comma, the first argument is considered as the
workerjs
filename or module name and rest all are ignored.
Platform Availability
- iOS
- Android
- Desktop Web