Sử dụng Promise.all với fetch

promise,fetch,async

Sử dụng Promise.all hiệu quả sẽ làm cho hiệu suất của code chúng ta tăng lên đáng kể. Và mã sau đây giúp các bạn có thể get được nhiều data mà không ảnh hưởng tới performance.

Tips: Tìm hiểu sâu về cách sử dụng Promise

async function getFullPost(){
  return await Promise.all([
     fetch('/post'),
     fetch('/comments')
  ]);
}
const [post, comments] = getFullPost();

Có thể bạn đã miss một số snippets code

JavaScript: async/await with forEach

JavaScript: async/await with forEach()

promise in javascript

promise in javascript

using Typescript callback style error handling

using javascript callback style error handling

Await in a for loop

How to Await in a for loop