Skip to content

Instantly share code, notes, and snippets.

@pionize
Created July 25, 2017 02:16
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pionize/0b439a150a0d8ddafae76805a2dbd270 to your computer and use it in GitHub Desktop.
//implements Promise
const getAllUsers = () => {
try {
getUsers()
.then(result => {
// this parse may fail
const data = JSON.parse(result)
console.log(data)
})
// uncomment this block to handle asynchronous errors
// .catch((err) => {
// console.log(err)
// })
} catch (err) {
console.log(err)
}
}
//implements async/await
const getAllUsers = async () => {
try {
// this parse may fail
const data = JSON.parse(await getUsers())
console.log(data)
} catch (err) {
console.log(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment