here is the problem I want to sumbit to you fellow gifted coders : I have a custom web container written in C++ that can communicate with javascript. From C++ to JS it can do synchronous JS function calls From JS to C++ it can do asynchronous C++ function calls
With these tools, I have to do a synchronous call from JS to C++... As I can't use message communication system (because it implies asynchronicity on the main thread unless I miss something), my first guess was to use worker thread
"main.js" file
var synctools = false;
var syncdata ="";
var myworker=new worker("demo_workers.js");
while(synctool == false){} //It s ugly but i haven t had any other ideas
"demo_workers.js" file
CallCPPFile(param,callback); //call the c++ and c++ call callback when finished
function callback(data)
{
//do stuff
syncdata = data;
synctools = true; //this is supposed to stop the looping of the main js
}
Unfortunatly, synctools and syncdata are not accessible from the worker thread. So here are a few questions :
- is there another method of communication between worker and main thread ? i have tried to use navigator object but it does'nt seem to work either (I don t know if its the same navigator object between the two threads)
- Apart from web worker, do you see another way I can achieve my goal ? (I tried promise too with no luck)
Thanks for your help