Created
May 2, 2018 02:30
-
-
Save whatwewant/fde524371910ba4d5afd28994cd84a2f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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