Skip to content

Instantly share code, notes, and snippets.

@sethbergman
Last active July 3, 2017 20:05
Show Gist options
  • Save sethbergman/3d95ea625dc05aaa3bf404eaa34701cb to your computer and use it in GitHub Desktop.
Save sethbergman/3d95ea625dc05aaa3bf404eaa34701cb to your computer and use it in GitHub Desktop.
await only works inside async functions
async function run () {
try {
const response = await fetch('/api/products')
const data = await response.json()
updateView(data)
} catch (err) {
console.log('Update failed', err)
}
}
(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