Waiting With Polling

From GreaseSpot

Jump to: navigation, search

This simple function will allow you to easily wait for an event (i.e. an AJAX load to populate the page with data), via polling.

function wait(check, callback){
  if (check()) callback()
  else window.setTimeout(wait, 300, check, callback);
}

Example usage:

wait(
  function(){ return count==0; },
  function(){ alert('allfound'); }
);
Personal tools