Skip to content

Instantly share code, notes, and snippets.

@googya
Last active May 3, 2018 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save googya/50e1b0e428f0ab5fb4c9016277ed431d to your computer and use it in GitHub Desktop.
Save googya/50e1b0e428f0ab5fb4c9016277ed431d to your computer and use it in GitHub Desktop.
轮询检查结果, 下次轮询时长为之前 1.5 倍
function delay(time, fn) {
return new Promise(function(resolve, reject){
function fun () {
resolve(fn())
}
setTimeout(fun, time);
});
}
function checkRes(time = 1000) {
let res = false
if (time > 4000) {
res = true;
}
let p = delay(time, () => (res))
p.then(e => {
if (!e) {
checkRes(time * 1.5)
} else {
console.log('finished')
}
})
}
checkRes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment