Created
December 9, 2021 09:54
-
-
Save adarsh-chakraborty/7b19af6b24a97ed323344a3efcd2b4e1 to your computer and use it in GitHub Desktop.
Fetch data with Promise concurrently
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
| let fetchData = async () => { | |
| const res = await fetch('https://bookshelf.gq/api/books'); | |
| const data = await res.json(); | |
| console.log('data is ready', data); | |
| const res2 = await fetch('https://dikz.herokuapp.com/api/latest'); | |
| const data2 = await res2.json(); | |
| console.log('data2 is ready!', data2); | |
| }; | |
| let fetchDataConcurrent = async () => { | |
| const res = fetch('https://bookshelf.gq/api/books').then((res) => res.json()); | |
| const res2 = fetch('https://dikz.herokuapp.com/api/latest').then((res) => | |
| res.json() | |
| ); | |
| const data = await Promise.all([res, res2]); | |
| console.log('data is ready', data[0]); | |
| console.log('data2 is ready!', data[1]); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment