Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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