Last active
May 3, 2018 09:58
-
-
Save googya/50e1b0e428f0ab5fb4c9016277ed431d to your computer and use it in GitHub Desktop.
轮询检查结果, 下次轮询时长为之前 1.5 倍
This file contains 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
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