Last active
July 3, 2017 20:05
-
-
Save sethbergman/3d95ea625dc05aaa3bf404eaa34701cb to your computer and use it in GitHub Desktop.
await only works inside async functions
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
async function run () { | |
try { | |
const response = await fetch('/api/products') | |
const data = await response.json() | |
updateView(data) | |
} catch (err) { | |
console.log('Update failed', err) | |
} | |
} |
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
(async () => { | |
try { | |
const response = await fetch('/api/products') | |
const data = await response.json() | |
updateView(data) | |
} catch (err) { | |
console.log('Update failed', err) | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment