class Ajax.PeriodicalUpdater
Description
Periodically performs an Ajax request and updates a container's contents based on the response text.
Ajax.PeriodicalUpdater behaves like Ajax.Updater, but performs the
update at a prescribed interval, rather than only once. (Note that it is
not a subclass of Ajax.Updater; it's a wrapper around it.)
This class addresses the common need of periodical update, as required by all sorts of "polling" mechanisms (e.g., an online chatroom or an online mail client).
The basic idea is to run a regular Ajax.Updater at regular intervals,
keeping track of the response text so it can (optionally) react to
receiving the exact same response consecutively.
Additional options
Ajax.PeriodicalUpdater features all the common options and callbacks
described in the Ajax — plus those added by Ajax.Updater.
It also provides two new options:
frequency(Number; default is2): How long, in seconds, to wait between the end of one request and the beginning of the next.decay(Number; default is1): The rate at which thefrequencygrows when the response received is exactly the same as the previous. The default of1meansfrequencywill never grow; override the default if a stale response implies it's worthwhile to poll less often. Ifdecayis set to2, for instance,frequencywill double (2 seconds, 4 seconds, 8 seconds...) each consecutive time the result is the same; when the result is different once again,frequencywill revert to its original value.
Disabling and re-enabling a PeriodicalUpdater
You can hit the brakes on a running PeriodicalUpdater by calling
Ajax.PeriodicalUpdater#stop. If you wish to re-enable it later, call
Ajax.PeriodicalUpdater#start.