Skip to content

Instantly share code, notes, and snippets.

@sagarpanda
Created April 8, 2020 11:37
Show Gist options
  • Select an option

  • Save sagarpanda/a2fd7f35a18ef4e9d1886aefa163a800 to your computer and use it in GitHub Desktop.

Select an option

Save sagarpanda/a2fd7f35a18ef4e9d1886aefa163a800 to your computer and use it in GitHub Desktop.
const shortPolling = (fn, interval) => {
let counter = 1;
const _interval = interval || 1000;
const next = (params) => {
setTimeout(() => {
counter += 1;
fn(next, counter, params);
}, _interval);
};
fn(next, counter);
};
shortPolling((next, counter) => {
console.log('hello', counter);
next();
}, 2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment