Tim and Everyone else that responded to this thread: THANKS!<br><br><br>I think tim hit is on the button with this: <br><br>&quot;functions like setTimeout() and asynchronous callbacks need to wait for the script engine to sleep before they&#39;re able to run.&quot;<br>
<br>I have been futzing around with a sort of wrapper for making JSON requests and just needed to ensure that a certain section<br>of code was &#39;atomic&#39;. Sounds like as long as i&#39;m not calling alert() in the middle of it, nothing to worry about: phew!<br>
<br>Interesting also to note the possibilities with threading in HTML5. Sounds like things are going to get *complicated*.<br><br>Anyways, thanks!<br><br>Erik<br><br><div class="gmail_quote">On Mon, Nov 3, 2008 at 10:40 PM, Tim Schaub <span dir="ltr">&lt;<a href="mailto:tschaub@opengeo.org">tschaub@opengeo.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hey-<br>
<div class="Ih2E3d"><br>
Erik Uzureau wrote:<br>
&gt; Dear OpenLayers users &amp; dev,<br>
&gt;<br>
&gt; Pardon the non-geo post, but I am wondering if anyone out there has come<br>
&gt; up across issues with<br>
&gt; synchronicity in javascript?<br>
&gt;<br>
&gt; After pouring over this stuff for several hours, I think I am pretty<br>
&gt; resolved to just say &quot;ok, javascript<br>
&gt; is event-driven and not truly multithreaded, so there is no need to worry&quot;.<br>
&gt;<br>
&gt; In the off-chance that someone out there might have information<br>
&gt; otherwise, please let me know.<br>
<br>
</div>I think the clearest answer is that event listeners and &quot;functions like<br>
setTimeout() and asynchronous callbacks need to wait for the script<br>
engine to sleep before they&#39;re able to run.&quot;<br>
<br>
Maybe you&#39;re concerned about something else, but if you&#39;re wondering<br>
whether a sequence of event handling code can be executed again before<br>
it has finished, the answer is no.<br>
<br>
Again, maybe you&#39;re reading up on mutexes for something else, but here&#39;s<br>
some code that demonstrates that you can&#39;t change the &quot;current&quot; value<br>
with subsequent triggers of the same event while the event handling code<br>
is executing, no matter how long it takes to run.<br>
<br>
function check(iter) {<br>
 &nbsp; &nbsp; var current;<br>
 &nbsp; &nbsp; document.body.onmousemove = function() {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; var start = (new Date).getTime();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; var id = start + Math.random();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; current = id;<br>
 &nbsp; &nbsp; &nbsp; &nbsp; // do something that takes a while<br>
 &nbsp; &nbsp; &nbsp; &nbsp; var a = [];<br>
 &nbsp; &nbsp; &nbsp; &nbsp; for(var i=0; i&lt;iter; ++i) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; a.push(i);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; }<br>
 &nbsp; &nbsp; &nbsp; &nbsp; var end = (new Date).getTime();<br>
 &nbsp; &nbsp; &nbsp; &nbsp; console.log(<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id + &quot; start: &quot; + start + &quot; end: &quot; + end +<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot; elapsed: &quot; + (end - start)<br>
 &nbsp; &nbsp; &nbsp; &nbsp; );<br>
 &nbsp; &nbsp; &nbsp; &nbsp; if(current != id) {<br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.error(id + &quot; failed&quot;);<br>
 &nbsp; &nbsp; &nbsp; &nbsp; }<br>
 &nbsp; &nbsp; }<br>
}<br>
<br>
// loop runs in &lt;1ms, events fired every ~17ms<br>
check(1000); &nbsp;// wiggle mouse over body<br>
<br>
// loop runs in ~25ms, events fired every ~45ms<br>
check(100000);<br>
<br>
// loop runs in ~225ms, events fired every ~250ms<br>
check(100000);<br>
<br>
You can do the same sort of thing with setTimeout.<br>
<br>
Tim<br>
<div class="Ih2E3d"><br>
&gt;<br>
&gt; Below are two of the links that have fed my brain for the last few hours:<br>
&gt;<br>
&gt; debate:<br>
&gt; <a href="http://stackoverflow.com/questions/124764/are-mutexes-needed-in-javascript" target="_blank">http://stackoverflow.com/questions/124764/are-mutexes-needed-in-javascript</a><br>
&gt;<br>
&gt; implementation of a mutex in js:<br>
&gt; <a href="http://www.developer.com/lang/jscript/article.php/3592016" target="_blank">http://www.developer.com/lang/jscript/article.php/3592016</a><br>
&gt; (note that his actual code for this *only* runs in ie, which obviously<br>
&gt; docks it a fair amount of credit)<br>
&gt;<br>
&gt; cheers,<br>
&gt; erik<br>
&gt;<br>
&gt;<br>
</div>&gt; ------------------------------------------------------------------------<br>
<div class="Ih2E3d">&gt;<br>
&gt; _______________________________________________<br>
&gt; Dev mailing list<br>
&gt; <a href="mailto:Dev@openlayers.org">Dev@openlayers.org</a><br>
&gt; <a href="http://openlayers.org/mailman/listinfo/dev" target="_blank">http://openlayers.org/mailman/listinfo/dev</a><br>
<br>
<br>
</div><font color="#888888">--<br>
Tim Schaub<br>
OpenGeo - <a href="http://opengeo.org" target="_blank">http://opengeo.org</a><br>
Expert service straight from the developers.<br>
</font><div><div></div><div class="Wj3C7c">_______________________________________________<br>
Dev mailing list<br>
<a href="mailto:Dev@openlayers.org">Dev@openlayers.org</a><br>
<a href="http://openlayers.org/mailman/listinfo/dev" target="_blank">http://openlayers.org/mailman/listinfo/dev</a><br>
</div></div></blockquote></div><br>