Skip to content

Instantly share code, notes, and snippets.

@mattiaslundberg
Created August 21, 2019 09:05
Show Gist options
  • Save mattiaslundberg/674f32960953512007ae47e7a9f2f1de to your computer and use it in GitHub Desktop.
Save mattiaslundberg/674f32960953512007ae47e7a9f2f1de to your computer and use it in GitHub Desktop.
async function main(url) {
const root = document.getElementById('root');
root.innerHTML = 'Hello world';
setTimeout(() => {
root.innerHTML = 'Something else';
}, 2000);
root.addEventListener('click', () => {
root.innerHTML = 'You clicked root!';
root.innerHTML = 'Hej Class!';
});
try {
const evt = await addEventPromise(root);
root.innerHTML = 'hello after await';
} catch {
root.innerHTML = 'Error from catch';
}
const promise = addEventPromise(root);
promise.then(evt => {
root.innerHTML = 'Hello from promise';
});
promise.then(evt => {
console.log('Hello from other promise then');
});
promise.catch(error => {
root.innerHTML = error.message;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment