Last active
December 27, 2017 19:17
-
-
Save Ibro/7ab993c8766dc70b099bde8b89f0e73a 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 someHelperFunctionThatReturnsPromise(value, error) { | |
console.log('Inside someHelperFunctionThatReturnsPromise()'); | |
return new Promise(function(resolve, reject) { | |
if (value) { | |
resolve(value); | |
} else { | |
reject(error); | |
} | |
}); | |
} | |
async function someAsyncFunctionThatAwaitsPromise(someValue) { | |
console.log('Inside someAsyncFunctionThatAwaitsPromise()'); | |
let value = await someHelperFunctionThatReturnsPromise(someValue); | |
return value; | |
} | |
async function anotherAsyncFunctionThatAwaitsAsyncFunction() { | |
console.log('Inside anotherAsyncFunctionThatAwaitsAsyncFunction()'); | |
let value = await someAsyncFunctionThatAwaitsPromise('CodingBlast'); | |
console.log(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment