Skip to content

Instantly share code, notes, and snippets.

@kartikpandey2
Created May 2, 2019 08:44
Show Gist options
  • Save kartikpandey2/77dd86071a7860f89fac9bba54300209 to your computer and use it in GitHub Desktop.
Save kartikpandey2/77dd86071a7860f89fac9bba54300209 to your computer and use it in GitHub Desktop.
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