Created
May 2, 2019 08:44
-
-
Save kartikpandey2/77dd86071a7860f89fac9bba54300209 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
const fetch1 = fetch(url).then((res) => res.json()). then((data) => {// do required things after fetch call and return Promise.resoove(true)}) | |
const fetch2 = fetch(url).then((res) => res.json()). then((data) => {// do required things after fetch call and return Promise.resolve(true)}) | |
const fetch3 = fetch(url).then((res) => res.json()). then((data) => {// do required things after fetch call return Promise.resolve(true)}) | |
const allFetchDone = Promise.all([fetch1, fetch2, fetch3]).then(() => {// this function will be called after all fetch request is completed with success}) | |
// this can be also done using async and await. This will make code Readable | |
// function for fetch call | |
const Fetch = async (url) => { | |
const response = await fetch(url) | |
return response.json() | |
} | |
const fetch1 = Fetch(url) | |
const fetch2 = Fetch(url) | |
const fetch3 = Fetch(url) | |
const allFetchDone = await Promise.all([fetch1, fetch2, fetch3]) | |
// to access fetch response of use index in allFetchDone array | |
// allFetchDone[0] will return response of fetch 1 | |
// Now do the required things | |
// This |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment