Last active
August 10, 2020 09:31
-
-
Save googya/75f83217ed19aeb01b571a498c07367b 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 fs = require('fs'); | |
function check_result() { | |
return fs.existsSync('foo.txt'); | |
} | |
function* infiniteSequence() { | |
let num = 1 | |
while (true) { | |
yield num | |
num = num * 2 | |
} | |
} | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve => { | |
resolve(fs.existsSync("foo.txt")) | |
}, ms)); | |
} | |
async function delayedChecking() { | |
let res = check_result(); | |
console.log(`result is ${res}`) | |
while (!res) { | |
let z = x.next().value; | |
console.log(`check ${z} milliseconds later`) | |
await sleep(z); | |
res = check_result() | |
} | |
} | |
let x = infiniteSequence() | |
delayedChecking(); |
Author
googya
commented
Aug 10, 2020
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment