Reputation: 4784
We have a Rails, Backbone app. The Rails server sends a lot of Pusher messages to different clients. A client usually depends on receiving messages in the correct sequence to some extent.
We have a few rare cases where the pusher messages are received (on the client) out of sequence, i.e. older messages sent by the server are received later than the newer messages. This only happens rarely, but we do want to tackle it.
Ideally, on the backbone client we would need some kinda of a buffer which stores out of sequences pusher messages, and waits for the rest to arrive for a short time.
My question is. This seems to be a common scenario in async apps. Are there JQuery libraries or other common techniques to tackle this scenario.
Upvotes: 0
Views: 344
Reputation: 708
Firstly, is there any reason to believe that the out-of-order messages could be caused by application logic? If not it's likely standard network issues, especially if this is rare.
Secondly, there aren't any libraries that I'm aware of but the logic shouldn't be too complicated to implement. You could store messages as they come in and use an ordering mechanism to know that things are ok, for example you could have an incrementing index number on each message, or use timestamps. Then you can either action the message if it's in order, or wait for a moment if not.
To be clear, Pusher sends messages in the order they're received so it's a problem with the network or your app, not the service.
Let me know if you do create a library for this! :)
Upvotes: 2