How to use workers?

nativescriptcore

#1

Update: Maybe its dumb question but… I don’t tested it on real device and workers must work on emulator?
here is my worker.js :

onMessage = function(msg){

if (msg.data == "close") {
    close();
    return;
}



for(let i=0;i < 20;i++){
    progressCallback(i);
}

postMessage({ res:"success"});

function progressCallback(value) {
    postMessage({ res: "progress", value: value });
}

}

and main.js:

    w = new Worker("~/workers/imageProcWorker");

    w.postMessage("test");

    w.onmessage = function (msg) {
        console.log("message from worker")
        if (msg.data.res == "progress") {
            console.log("Progress: ",msg.data.value);
            return;
        }

        if (msg.data.res == "success") {
            loader.hie();
            w.terminate();
        }
    }

its not working :frowning: something is wrong with this code? (NativesCript Core)