On Wed, 31 Mar 2010 09:38:21 +0300, Jonas Sicking <jo...@sicking.cc> wrote:

On Tue, Mar 30, 2010 at 9:56 PM, Boris Zbarsky <bzbar...@mit.edu> wrote:
On 3/30/10 10:22 AM, Jonas Sicking wrote:

Making it implementation dependent is likely to lead to website
incompatibilities. Such as:

ws = new WebSocket(...);
ws.onopen = function() {
  ws.send(someString);
  if (ws.bufferedAmount>  X) {
    doStuff();

Can bufferedAmount not change due to data actually hitting the network
during the execution of this code? As in, will all the someString data be
buffered immediately after that send() call?

I would have expected bufferedAmount to only change as a result of an
event being posted to the main event loop.

I'm certainly no EcmaScript expert but now I'm confused. What event would that be? There is no 'onsent' event. Would bufferedAmount not change until there is an 'onerror' or 'onclosed' event?

BR,
 /niklas


We generally try to avoid "racy" variables since people don't expect them. Consider for example

if (ws.bufferedAmount > X) {
  setUpSomeState();
}

try {
  doOtherThings();
}
finally {
  if (ws.bufferedAmount > X) {
    cleanUpState();
  }
}

I'd imagine most JS developers to expect the cleanup to always happen
if the setup did.



--
Niklas Beischer
Software Developer
Opera Software

Reply via email to