we are developing a web application using GWT in the front end.
In GWT we make calls to the server by appending javascript code as stated below:
public native static void call(int requestId, String url, ICall handler) /*-{
var callback = "callback" + requestId;
//Create a script element.
var script = document.createElement("script");
script.setAttribute("src", url+callback);
script.setAttribute("type", "text/javascript");
script.setAttribute("async", "true");
//Define the callback function on the window object.
window[callback] = function(response) {
[email protected]::handleResponse(Ljava/lang/String;)(response);
}
//Attach the script element to the document body.
document.body.appendChild(script);
}-*/;
Some calls take a minute to complete and some others just a couple of seconds. If we make multiple calls at the same time all of them are executed in parallel . This means that a call that ends in 2 seconds does not have to wait until a call that lasts a minute finish. This is true in Chrome and Safari. However Firefox waits until the first invoked function finishes to start the other functions.
Why does Firefox waits until a javascript function is finished to start another function? How to fix this?
Thanks
You can use HTML5 with multithreaded JavaScript through web workers. First check if your browser supports this.
function supports_web_workers() {
return !!window.Worker;
}
Then start using multithreading.
// thread1
var myBread = new Worker('bread.js');
// thread2
var myButter = new Worker('butter.js');
I never tried this myself so correct me if I'm wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With