Created
April 10, 2018 05:04
-
-
Save agm1984/193e941ba3013fad19dc3553104c0b46 to your computer and use it in GitHub Desktop.
JavaScript: is return await needed? sometimes.
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
// INCLUDING AWAIT DELEGATES TO PARENT | |
const dontBubbleUp = async () => { | |
const samplerPack = async () => { | |
throw new Error('BAD') | |
} | |
try { | |
return await samplerPack() | |
} catch (e) { | |
throw new Error('handling rejection upstream in parent') | |
} | |
} | |
dontBubbleUp() | |
.then(res => console.log('End of chain reached.', res)) | |
.catch(err => console.log('YOLO TEST 1:\n', 'End of chain reached.', err)) | |
// EXCLUDING AWAIT HANDLES FIRST AT CALL SIGHT | |
const bubbleUp = async () => { | |
const newSamplerPack = async () => { | |
throw new Error('handling error in newSamplerPack first') | |
} | |
try { | |
return newSamplerPack() | |
} catch (e) { | |
throw new Error('handling error locally') | |
} | |
} | |
bubbleUp() | |
.then(res => console.log('End of chain reached.', res)) | |
.catch(err => console.log('YOLO TEST 2:\n', 'End of chain reached.', err)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment