Created
August 4, 2019 09:52
-
-
Save mattiaslundberg/b7d6b6b0933bb59bc4aa2b9f29da0ccc to your computer and use it in GitHub Desktop.
FooCoding s01 Promises
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
// Create new promise | |
const p = new Promise((resolve, reject) => { | |
reject(new Error('some error')); | |
//resolve('Some data'); | |
}); | |
// Then/catch | |
p.then(result => console.log(result)).catch(error => console.error(error)); | |
// Async | |
const foo = async () => { | |
try { | |
const result = await p; | |
console.log(result); | |
} catch (error) { | |
console.log('it crashed', error); | |
} | |
}; | |
foo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment