> Javascript is single-threaded so you don't have to worry about a mutex.
ahh, whew. so - whilst AJAX can do simultaneous HTTP requests, the
actual execution of functions is forced to be one at a time. whew :)
> This is just an outline of how it could work, not a well-thought-out
> proposal.
ack.
> 1. Your initial download adds a setModulesCompleteCallback(n, function()
> {...}) call based on the number of modules to download, before any script
> tags are added
> 2. A script tag is inserted for each module you want to load
> 3. At the end of each module, top-level code is added to call
> notifyModuleDone(), which decrements the count of modules waiting to load.
> If 0, it then calls the callback function supplied in #1.
>
> Note that you lose failure reporting using script tags, but you can still
> have an overall timeout that will fail if all the modules aren't loaded in
> 60s or whatever.
( improvements later - retries on script loads? is that possible?
can you catch errors of individual script load failures? )
> > are you saying, then, that it would be reasonable to make this "array-
>
> > checking" be activated on a callback?
>
> Yes, but it can be even easier than that.
okaaay. cool.
> > it would be necessary ensure that the "everything is loaded" is not
> > called more than once by multiple AJAX loads finishing all at once
> > resulting in multiple simultaneous callbacks.
>
> There is no "simultaneous callback" in JS as it is single threaded.
ack.
> > all of this was the primary motivation behind doing the timer, but i
> > really _do_ want a solution to the async module import problem i've
> > created :)
>
> It still has to be asynchronous, since you can't block the browser event
> loop from running while downloading them, so your code has to exit back to
> the top of the event loop. Even if you could block the event loop, you
> wouldn't want to as the browser would bcome unresponsive.
yehh, i found people trying to do "sleep" in all sorts of weird ways
- one of which was creating a hidden modal dialog box with a URL
target of a javascript function "setTimeout(window.close, NNNN)" !!
only works in IE.
--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---