I have Coffeescript code running in playframework which builds a table based on several AJAX queries.
$.get "/queues", (queues) ->
$.each queues, (index, queue) ->
$.get "/queue/" + queue, (html) ->
$("#queues").append $("<tr>").html html
/queues returns a list of queue names.
/queue/name returns HTML describing queue
#queues is a table, where I display that description.
This all works fine, but since the queries are asynchronous, the append calls are executed in a different order each time, which means that the table contents are randomly reordered every time the query runs. Since this is providing the current status of a dynamic, the query runs every three seconds.
What is a good way to have the rows be displayed in a consistent order every time? I have
index, so I could try adding the data into that row, but if the third query returns first, adding it to row three is not going to work well.
I do not have a strong preference about how the ordering is done, just that it is consistent over multiple loads.