Created
December 24, 2017 13:33
-
-
Save Ibro/370aae1a50491bbe267fd7eed472259e to your computer and use it in GitHub Desktop.
JavaScript Promises, road to async/await - https://codingblast.com/javascript-promise-async-await
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
function someFunction(value, error) { | |
return new Promise(function(resolve, reject) { | |
if (value) { | |
resolve(value); | |
} else { | |
reject(error); | |
} | |
}); | |
} | |
async function mainFunction() { | |
try { | |
let value = await someFunction(null, 'Some error'); | |
console.log(value); | |
} catch (error) { | |
console.error(error); | |
} | |
} | |
mainFunction(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment