WebSocketBundle icon indicating copy to clipboard operation
WebSocketBundle copied to clipboard

multiple socket/connect event race condition?

Open zeckon opened this issue 8 years ago • 1 comments

My app subscribes to 2 different topics. However the second one is a little below in the code.

I suspect, time to time the second event doesn't register before connect, so it doesn't run.

It seems ab.connect gets the connect callback as a parameter but ws.connect doesn't. It's set with the on method.

What is the safest way to register multiple connect events callbacks and ensure that they register before the connect happens and they run?

Thanks

zeckon avatar Sep 09 '16 09:09 zeckon

Here is a sample code var websocket = WS.connect("ws://localhost:8080");

websocket.on("socket/connect", function(session){ console.log('running'); });

/// .... SOME OTHER CODE

websocket.on("socket/connect", function(session){ console.log('Sometimes not running'); });

zeckon avatar Sep 09 '16 09:09 zeckon