Skip to content

Instantly share code, notes, and snippets.

@marcoalbarelli
Created February 28, 2019 11:46
Show Gist options
  • Save marcoalbarelli/16dcfedb26196140e3f7b11a468e5e85 to your computer and use it in GitHub Desktop.
Save marcoalbarelli/16dcfedb26196140e3f7b11a468e5e85 to your computer and use it in GitHub Desktop.
const throwing = () => {
throw Error('eee')
}
const throwingAsync = async () => {
throw Error('eee')
}
const rejectingButNotReturning = () => {
return Promise.reject(Error('aaa'))
}
const rejectingButNotReturningAsync = async () => {
Promise.reject(Error('aaa'))
}
const rejectingAndReturning = async () => {
return Promise.reject(Error('aaa'))
}
(function(){
const args = process.argv
const availableFunctions = [
'throwing',
'throwingAsync',
'rejectingButNotReturning',
'rejectingButNotReturningAsync',
'rejectingAndReturning'
]
if(!args[2]) {
return console.log(`Choose a function. Available ones are: ${availableFunctions.join(' ')}`)
}
switch(args[2]) {
case 'throwing':
return throwing()
case 'throwingAsync':
return throwingAsync()
case 'rejectingAndReturning':
return rejectingAndReturning().catch(console.log)
case 'rejectingButNotReturningAsync':
return rejectingButNotReturningAsync().catch(console.log)
case 'rejectingButNotReturning':
return rejectingButNotReturning()
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment