Skip to content

Instantly share code, notes, and snippets.

@whatwewant
Created May 2, 2018 02:30
Show Gist options
  • Save whatwewant/fde524371910ba4d5afd28994cd84a2f to your computer and use it in GitHub Desktop.
Save whatwewant/fde524371910ba4d5afd28994cd84a2f to your computer and use it in GitHub Desktop.
const callback = () => console.log('done');
const getStatus = () => !!Math.round(Math.random());
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
function polling(getStatus, callback) {
let delta = 1000;
let start;
return async function idle() {
if (getStatus()) {
console.log('idle');
await delay(delta);
delta *= 1.5;
return idle();
}
return callback();
};
}
polling(gs, cb)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment