PDA

View Full Version : [solved] Delay starting PollingProvider



rblon
20 Nov 2009, 6:09 AM
I am using a polling provider with an interval of 300 seconds.



Ext.Direct.addProvider({
id: 'poll',
type: 'polling',
url: 'poll.php',
interval: 300000
});
Now, I would like to have the first poll request 300 seconds after page loading instead of directly after loading. My workaround is



Ext.Direct.getProvider('poll').disconnect();
setTimeout("Ext.Direct.getProvider('poll').connect()", 300000);
but I am wondering if there is a cleaner/better way to do this?

aconran
23 Nov 2009, 9:38 AM
Ext adds on a couple of convenience methods to all functions within JavaScript one of them is defer.

Defer allows you to defer/delay a functions execution and further specify what scope it will run in (the context of this) and any additional arguments you'd like to pass to it.

Try this:


var dp = Ext.Direct.getProvider('poll');
dp.disconnect();
dp.connect.defer(30000, dp);

rblon
23 Nov 2009, 12:42 PM
thx, defer seems a useful extjs function I wasn't aware of