Skip to content

Instantly share code, notes, and snippets.

@iamlucianojr
Last active May 4, 2019 11:32
Show Gist options
  • Save iamlucianojr/7faa865e91e830a3470ed7a060dae62b to your computer and use it in GitHub Desktop.
Save iamlucianojr/7faa865e91e830a3470ed7a060dae62b to your computer and use it in GitHub Desktop.
async function functionName (arguments) {
// Do something asynchronous
}
const functionName = async (arguments) => {
// Do something asynchronous
}
jeffBuysCake('black forest')
.then(partyAsPlanned)
.catch(buyCakeYourself) // Grumble Grumble... #*$%
const promise = jeffBuysCake('black forest')
.then(cake => console.log(cake))
.catch(nocake => console.log(nocake))
const jeffBuysCake = cakeType => {
return new Promise((resolve, reject) => {
// Do something here
})
}
const jeffBuysCake = cakeType => {
return new Promise((resolve, reject) => {
setTimeout(()=> {
if (cakeType
- = 'black forest') {
resolve('black forest cake!')
} else {
reject('No cake 😢')
}
}, 1000)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment