views:

229

answers:

1

Hi All, I have a web app, whose UI is written in GWT, where for various reasons I need to resize the active window when the server reports things. To do this I use a JSNI function which uses resizeTo and everything works great. I did a small test and tried sending a few updates from the server and got an "Access is denied" error from the resizeTo command. After googling a bit I discovered that this is because the browser is still busy with another resizeTo command and throws an exception due to that. My question is if anyone has a good way to see if the browser is ready/available to be resized? A current workaround I'm thinking, but I don't particularly like, is having a try { } catch() block and if an exception is thrown then catch it and call the function again in timeout but I would like to have a more straightforward way.

Thanks, Ittai

EDIT: I thought of another problem though, what if update A and update B return together from the server and A starts while B sleeps for X ms, in the mean time update C is sent from the server and finds that A is finished although B hasn't awaken yet so C executes and only then B which is wrong because B does not contain the most recent size. Do you have an idea for a solution? Is that a race condition problem? Thanks

+1  A: 

Ittai,

If I were a lazy man (and I am) I would use jQuery's resize() because it gives you a callback:

http://docs.jquery.com/Events/resize

You can do something like

ready = false;
$(window).resize(function(){
    ready = true;
});

Noah

Noah
Hi Noah, thanks for the heads up on jquery. As I'm using GWT the solution for me will probably be to use gwtquery which is a jquery clone for gwt. Hope this works. I thought of another problem though, what if update A and update B return together from the server and A starts while B sleeps for X ms, in the mean time update C is sent from the server and finds that A is finished although B hasn't awaken yet to C executes and only then B which is wrong because B does not contain the most recent size. Do you have an idea for a solution? Is that a race condition problem? Thanks
Ittai
Yes, generally I would suggest that you look into mutexes and semaphores. This may help: http://www.developer.com/lang/jscript/article.php/3592016/AJAX-from-Scratch-Implementing-Mutual-Exclusion-in-JavaScript.htm
Noah