<span class="Apple-style-span" style="-webkit-text-stroke: none; -webkit-transform-origin-z: 0px; -webkit-transform-style: 50%; ">On Fri, Nov 20, 2009 at 1:10 PM, Greg Wilkins <span dir="ltr"><<a href="mailto:gregw@mortbay.com">gregw@mortbay.com</a>></span> wrote:</span><br>

<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">Fumitoshi Ukai (鵜飼文敏) wrote:<br>
> On Thu, Nov 19, 2009 at 1:00 PM, Greg Wilkins <<a href="mailto:gregw@webtide.com">gregw@webtide.com</a><br>
><br>
</div><div class="im">>      var ws = new WebSocket("ws://<a href="http://mysite.com" target="_blank">mysite.com</a><br>
</div>>     <<a href="http://mysite.com" target="_blank">http://mysite.com</a>>","myprotocol");<br>
> ...<br>
<div class="im">>     So if the next line in the script is<br>
><br>
>      ws.onopen=myopenfunc;<br>
><br>
>     there is a race between if the onopen function will<br>
>     be assigned and if the background connection has been established?<br>
><br>
><br>
> I believe open event  is just queued at the moment, and it will be fired<br>
> later when javascript becomes idle.<br>
<br>
</div>Unfortunately this does not appear to be the implementation in chrome<br>
at least.  If you step through with a debugger, then the close happens<br>
before my ws.onclose function is assigned, as thus it is never called.<br></blockquote><div><br></div><div>Really?</div><div>I couldn't reproduce the case.  <span class="Apple-style-span" style="-webkit-text-stroke: none; -webkit-transform-origin-z: 0px; -webkit-transform-style: 50%; ">I put long for loop between new WebSocket and ws.onopen =, and/or ws.onclose, it will fire onopen and onclose as expected <span class="Apple-style-span" style="-webkit-text-stroke: none; -webkit-transform-origin-z: 0px; -webkit-transform-style: 50%; ">after chrome showing the page is unresponsive.</span></span></div>

<div><span class="Apple-style-span" style="-webkit-text-stroke: none; -webkit-transform-origin-z: 0px; -webkit-transform-style: 50%; "><span class="Apple-style-span" style="-webkit-text-stroke: none; -webkit-transform-origin-z: 0px; -webkit-transform-style: 50%; "><br>

</span></span></div><div><span class="Apple-style-span" style="-webkit-text-stroke: none; -webkit-transform-origin-z: 0px; -webkit-transform-style: 50%; "><span class="Apple-style-span" style="-webkit-text-stroke: none; -webkit-transform-origin-z: 0px; -webkit-transform-style: 50%; "><div>

var ws = new WebSocket("ws://localhost:8880/websocket/tests/simple");</div><div>debug("wait");</div><div>for (var j = 0; j < 50000; j++) {</div><div> for (var i = 0 ; i < 100000; i++) {</div><div>

  ;</div><div> }</div><div>}</div><div>debug("wait done");</div><div><br></div><div>ws.onopen = function()</div><div>{</div><div>    debug("Connected.");</div><div>};</div><div><br></div><div>ws.onmessage = function(messageEvent)</div>

<div>{</div><div>    debug("Received: '" + messageEvent.data + "'");</div><div>};</div><div><br></div><div>ws.onclose = function()</div><div>{</div><div>    debug("Closed.");</div><div>

    endTest();</div><div>};</div><div><br></div></span></span></div><div><span class="Apple-style-span" style="-webkit-transition: 0px; ">-- </span></div><div><span class="Apple-style-span" style="-webkit-transition: 0px; ">ukai</span></div>

<div><span class="Apple-style-span" style="-webkit-transition: 0px; "><br></span></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Even if it was implemented as you say, I'm wondering if the API should<br>
be less dependent on the single threaded nature of current javascript<br>
implementations.<br>
<br>
cheers<br>
</blockquote></div><br>