Client side part of my application needs to process WebSocket messages in strict order. Unfortunately each message is processed quite long (about 3 seconds), so another appears before the first one has ended. After few messages the order is totally different. How to solve this problem in JavaScript.
I thought about a task queue, but I don’t know how to implement it to not block GUI of my web app.
At this time, the WebSocket API in browsers does not expose a frame based or streaming option/API. So there is not really an option to accomplish this natively.
That means you need to create your own logic / structure within the data packets you’re sending from your server to clients. That should be a relatively easy task, I could think of transmitting simpl JSON strings/objects which might have a indexed property on top level.
and your client script would need to look into each arriving packet and sort things out correctly (keeping track of arrived packets and “hold + wait” if a packet with a too high indexed arrived)