Skip to content

Instantly share code, notes, and snippets.

@tanepiper
Last active November 13, 2017 14:31
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 tanepiper/de4b5df791a6bef517445e1e4dce4e4f to your computer and use it in GitHub Desktop.
Save tanepiper/de4b5df791a6bef517445e1e4dce4e4f to your computer and use it in GitHub Desktop.
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