On Fri, Mar 13, 2009 at 11:26 AM, lkcl <[email protected]> wrote:

> i'm trying to get my head round that idea, in combination with firing
> off several script-injections (using scriptnode.src = "./
> Window.cache.js" etc. not scriptnode.text = ".......")
>
>  ... and it's not working - the thought of having to protect a counter
> with a mutex, in javascript, makes my head spin :)
>

Javascript is single-threaded so you don't have to worry about a mutex.

This is just an outline of how it could work, not a well-thought-out
proposal.

   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.

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.


> 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.


> 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.

-- 
John A. Tamplin
Software Engineer (GWT), Google

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/Google-Web-Toolkit-Contributors
-~----------~----~----~----~------~----~------~--~---

Reply via email to