Skip to content

Instantly share code, notes, and snippets.

@coltpini
Last active May 5, 2017 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coltpini/3995511c0bf9ae7ad196e9997c1643f8 to your computer and use it in GitHub Desktop.
Save coltpini/3995511c0bf9ae7ad196e9997c1643f8 to your computer and use it in GitHub Desktop.
// 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