Web Worker APIs

Deprecation notice
CheerpJ 2 is deprecated. Consider migrating to CheerpJ 3 .

JavaScript Web Worker API

CheerpJWorker

The main entry point for CheerpJ workers is the CheerpJWorker JS interface. It is a normal JS object and it is possible to instantiate it multiple times.

var w = new CheerpJWorker();
w.cheerpjInit().then(function (e) {
console.log("CheerpJWorker is ready");
});

For more information visit the Using Web Workers guide.

CheerpJWorker.cheerpjRunMain

cheerpjRunMain(className, classPath, ...)

Runs a Java main method in the WebWorker context

w.cheerpjRunMain("ClassName", classPath, arg1, arg2).then(...)

CheerpJWorker.cjCall

cjCall(objOrClassNameOrInvoker, methodName, ...)

Executes a static Java method in the WebWorker content

w.cjCall("ClassName", "methodName", arg1, arg2).then(...)

CheerpJWorker.cjResolveCall

cjResolveCall(className, methodName, types)

Uses Java reflection to resolve the method and returns an opaque handle to it. This handle can then be used multiple times without using Java reflection again.

w.cjResolveCall("ClassName", "methodName", null).then( // or array of parameter types if methodName is not unique
function(resolvedMethod) {
w.cjCall(resolvedMethod, arg1, arg2);
...
}
);

CheerpJWorker.cjFileBlob

cjFileBlob(fileName)

Used to download files from the CheerpJ filesystem. It returns a promise that eventually resolve to a Blob object, which can be downloaded with standard HTML5 techniques.

CheerpJWorkercheerpj.AddStringFile

AddStringFile(fileName, str)

Used to add files into the /str/ mount point filesystem.

Java Web Worker API

Worker

Initializes the Worker object, this method is blocking.

Worker w = new Worker();

runMain

Runs the main method of the given class in the Web Worker context, this method is blocking.

ParametersOutput
String className, String classPath, Object… argNone
w.runMain("Hello", "");

call / callI / callD / callL (for static method)

Runs the given static method in the Web Worker context, this method is blocking

callI, callD and callL should be used when primitives are expected.

MethodParametersOutput
callString className, String methodName, Object… argObject
callIString className, String methodName, Object… argInt
callDString className, String methodName, Object… argDouble
callLString className, String methodName, Object… argLong

resolveCall

Returns an handle to a resolved method, this method is blocking.

ParametersOutput
String className, String methodName, String[] typesObject

call / callI / WcallD / callL (for resolved method)

Runs the given resolved method handle in the Web Worker context, this method is blocking

MethodParametersOutput
callObject resolvedFunc, , Object… argObject
callIObject resolvedFunc, , Object… argInt
callDObject resolvedFunc, , Object… argDouble
callLObject resolvedFunc, , Object… argLong

Further reading

Was this page helpful?
Suggest changes