Last active
May 5, 2017 23:24
-
-
Save coltpini/3995511c0bf9ae7ad196e9997c1643f8 to your computer and use it in GitHub Desktop.
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
// Multiple sources with the callback pattern | |
getData((a) => ( | |
getMore(a, b => ( | |
andEvenMore(b, c=> ( | |
andLastlyMore(c, d => ( | |
// do something with d | |
) | |
) | |
) | |
); | |
// same thing but now with promises | |
getData() | |
.then( (a) => getMore(a) ) | |
.then( (b) => andEvenMore(b) ) | |
.then( (c) => andLastlyMore(c) ) | |
.then( (d) => /* do something with d */ ) | |
// and lastly, the same thing but with async & await | |
async getMyData(){ | |
const a = await getdata(); | |
const b = await moreMore(a); | |
const c = await andEvenMore(b); | |
const d = await andLastlyMore(c); | |
// do somthing with d; | |
// and you have access to a,b,c also. | |
// and you can return d here. | |
return d | |
} | |
// the async function gets returned as a promise. | |
getMyData.then( (d) => { /* do something with what was returned. */ } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment