Created
September 8, 2022 03:11
-
-
Save rajatjain-21/0f0fcceff5f3a916f32c64839e35e977 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ------------------------------------------------------------------- | |
// 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