Skip to content

Instantly share code, notes, and snippets.

@marcojetson
Created May 17, 2017 08:30
Show Gist options
  • Save marcojetson/cc06400ba3473046007372ee03aa782e to your computer and use it in GitHub Desktop.
Save marcojetson/cc06400ba3473046007372ee03aa782e to your computer and use it in GitHub Desktop.
/**
* Executes a function with a given interval
* @arg {function} fn - Function to execute,
* @arg {integer} interval - Interval in milliseconds
*/
function poll(fn, interval) {
fn(() => setTimeout(() => poll(fn, interval), interval));
}
poll(retry => $.get('/status').success(res => res.status === 'pending' && retry()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment