PDA

View Full Version : Sending only the last call from many requests



delp
3 Mar 2014, 8:33 AM
I've been searching through the online docs and I'm certain I read about this feature while looking at something else... but can I find it now?

If I have a compenent and it can make a few calls in very quick order to the server but I only wish the send the last one - what are the properties (link to in the docs would do)?

I'm not after the enableBuffer as I want that to be false (so many different calls can be made at same time), but for specific calls I only want to do the last one if say 3 of the same requests are made in say a 20ms timeframe.

carol.ext
3 Mar 2014, 10:37 AM
Not sure of the context of your requests. If it is an event handler, you can specify a buffer in the options.

http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.util.Observable-method-addListener


buffer : Number

Causes the handler to be scheduled to run in an Ext.util.DelayedTask delayed by the specified number of milliseconds. If the event fires again within that time, the original handler is not invoked, but the new handler is scheduled in its place.

delp
3 Mar 2014, 12:42 PM
Yes that might have been what I read previously - although I thought I read it in the context of sending requests (as that's what I want).

So if I had a directFn as part of a store and that function was called twice in the space of 20ms then I want it to ignore the first call. So its virtually the same as the buffer for the event handler, but for use when calling direct functions.

Piruthu
4 Mar 2014, 1:11 AM
try using DelayedTask (http://docs.sencha.com/extjs/4.2.2/#!/api/Ext.util.DelayedTask)inside directFn



DelayedTask - .. When called, the task will wait the specified time period before executing. If during that time period, the task is called again, the original call will be cancelled. This continues so that the function is only called a single time for each iteration.

delp
4 Mar 2014, 1:49 PM
Yes that's what I'll have to do, but would be nice if it was inbuilt into the proxy or similar.