1

We have a web calendar client which shows events in real time. Whenever there is an update on the server, we use Ably Realtime to notify the client that it needs to request updates from the server. The client then uses an Ajax call to get the updated info from the server.

The problem is that there are multiple updates happening and sometimes a new Ajax call is started before the old one is completed. The problem is how do we get the 2nd Ajax call to execute only after the first one completes.

Example code:

channel.subscribe(function(message) { $.ajax({...}) });
user1480192
  • 665
  • 8
  • 23
  • 2
    see this add ajax req. in a que https://stackoverflow.com/a/31149750/9641914 – Satish Patil Mar 16 '20 at 13:03
  • Hi, I'm a dev advocate at Ably. Out of interest, why aren't you keeping the connection between your calendar client and your server always open (via Ably), so that there's no problem with the message ordering in the first place? Are the updates not frequent enough? – Srushtika Neelakantam Mar 16 '20 at 13:10
  • The connection is always open. However we are maintaining an existing system which we can not change in which the event information is obtained via ajax. So what we are trying to do is instead of the client polling the server to see if there are changes, have the server push a call to action to the client if there is a change, and then the client makes an ajax request to get the new data. – user1480192 Mar 18 '20 at 06:12

1 Answers1

0

An Ably Engineer here,

What's happening now is that your AJAX calls can take any amount of time and you may receive more messages inside that window, and these newer calls could finish faster.

We can't make your Ajax calls be synchronous, but you can. Instead of just firing them off as the message from Ably arrives, what you can do is add the update calls to a list and have a function that consumes these updates one by one in order.

Ben Gamble
  • 66
  • 4