Skip to content

Instantly share code, notes, and snippets.

@rajatjain-21
Created September 8, 2022 03:11
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 rajatjain-21/0f0fcceff5f3a916f32c64839e35e977 to your computer and use it in GitHub Desktop.
Save rajatjain-21/0f0fcceff5f3a916f32c64839e35e977 to your computer and use it in GitHub Desktop.
// -------------------------------------------------------------------
// this function simulates a request that needs to run async
// -------------------------------------------------------------------
function doOtherAsyncThing() {
return new Promise((resolve) => {
setTimeout(() => resolve('it’s done!'), 500);
});
}
// -------------------------------------------------------------------
// this is the code that actually loads data
// -------------------------------------------------------------------
function getData() {
fetch('https://blogger.ceo/api/blogs/image/random')
.then((response) => response.json())
.then((response) => {
doOtherAsyncThing().then((otherResponse) => {
// do stuff with `response` and `otherResponse`
console.log({ response, otherResponse });
});
});
}
getData();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment