View Full Version : Handling batched responses

28 Oct 2009, 5:38 PM
Well - batched requests get collected using an interval - two requests that get fired within 100 ms can get collected into one batched request. So far, so good.

What about the handling of callbacks of those batched requests? Take for an example the "write"-event of a store: If the response of a batched request (using a store) gets interpreted, this listener is called twice without a delay. Take a batched update/destroy request as an example: The call for the destroy method on the server might return "success==false", whereas the call for the update method might return "success=true". What if your callback needs to be aware of the success property and invoke appropriate action based on that?

In my example, I want to close a dialog right after a (batched) request has been processed, if, and only if the (batched) request succeeded with the success property set to "true" in every case. This is fine for single requests - and in some cases, for a specific order the responses get merged together.

There are three alternatives:
1) Configure the response to hold only ONE success property, regardless of the number of requests that were batched together. This success property would then be set to "false" as soon as any method on the server sets its success property to "false" (10 requests: 9 successfull, 1 failed: Whole batch operation marked as failed, i.e. success == false).
This would mean some server-side coding, and implementing functionality into the Ext.Direct-API, so that only one success property is expected by the client
2) Implement appropriate functionality into the Ext.Direct-API, and leave server-side code as is. This could mean - for example - that Ext.Direct parses the response, splits batched responses and investigates the success properties - and triggers the appropriate event only ONCE for the whole response, and not for every splitted response. The events should then pass ALL splitted responses to only one function call.
3) Implement functionality in userland API: Add some kind of Task that diffs in a given interval some return parameter of the listeners, and see whether any of this return value is false.

Any thoughts? Best practices? Future plans on how Ext.Direct manages batched responses?

Point 2 seems to be reasonable - but then again we would need another config property that tells which actions might get batched. Otherwise, handling a single callback for 4 batched requests that are logically not related could become a pita.