Wait For All synchronization pattern in Javascript
<p>A <code>JS</code> control calls a data service and continues rendering itself without waiting for the result. Sometimes the service returns after the the controls is being fully rendered, sometimes - before. How do you implement <code>WaitForAll</code> in <code>JS</code>? I'm using <code>jQuery</code>.</p>

<p><strong>Here's what I've done myself: (Utils.WaitForAll simply counts the number of hits once it's matched with the count it calls handle)</strong></p>

<pre><code>// before we started
var waiter = Utils.WaitFor({handle: function(e){ alert("got called"; }, count: 2});
</code></pre>

<p>the way it gets triggered:</p>

<pre><code>// place one
waiter.Notify({one: {...}});
</code></pre>

<p>and then</p>

<pre><code>// place two (can occur before one though)
waiter.Notify({two: {...}});
</code></pre>

<p>which triggers handle, handle has values tagged as <code>one</code> &amp; <code>two</code> in its <code>e</code>. Waiter is an extra 'global' var, travelling down the stack, which i didn't quite like and it's a another new object after all... Any obvious problems with my approach?</p>
