Skip to content

Instantly share code, notes, and snippets.

@mattiaslundberg
Created August 4, 2019 09:52
Show Gist options
  • Save mattiaslundberg/b7d6b6b0933bb59bc4aa2b9f29da0ccc to your computer and use it in GitHub Desktop.
Save mattiaslundberg/b7d6b6b0933bb59bc4aa2b9f29da0ccc to your computer and use it in GitHub Desktop.
FooCoding s01 Promises
// 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