Created
February 28, 2019 11:46
-
-
Save marcoalbarelli/16dcfedb26196140e3f7b11a468e5e85 to your computer and use it in GitHub Desktop.
This file contains 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
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