Last active
November 13, 2017 14:31
-
-
Save tanepiper/de4b5df791a6bef517445e1e4dce4e4f to your computer and use it in GitHub Desktop.
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
const e = document.createDocumentFragment('div'); | |
const sleep = (ms, caller, ...args) => new Promise(resolve => setTimeout(caller || resolve, ms, ...args)); | |
const waitForHello = async(timeout, elm) => { | |
console.log('checking'); | |
if (elm.innerHTML === 'Hello world') { | |
console.log('Value found'); | |
return; | |
} else if ((timeout -= 100) <= 0) { | |
throw ('Timed out'); | |
} | |
await sleep(100, waitForHello, timeout, elm); | |
} | |
(async ()=>{ | |
e.innerHTML = 'waiting..' | |
//sleep(100, () => e.innerHTML='Hello world'); | |
try { | |
await waitForHello(2000, e); | |
} catch (error) { | |
throw error; | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment