avatar
Untitled

Guest 814 7th Feb, 2025

const getUsers = async () => {
	return ajax.get('get_user');
  	// Ở đây anh không cần return ajax.get...
   	// Mà anh có thể const users = await ajax.get('get_user');
  	// Sau đó anh thêm sửa xóa danh sách users
    // Rồi return users
};

const getNotis = async () => {
	return await ajax.get('get_notis');
}

const getUsersAndNotis = async () => {
  	const [users, notis] = await Promise.all([getUsers(), getNotis()]);

  	// Promise.all trả về 1 array, ở đây em mapping lại thành 1 object (cho nó tường minh hơn là mình muốn trả về đối tượng nào)
  	return {
    	users: users,
      	notis: notis,
    };
}


// Dùng async với function bình thường
// Còn 2 cái trên em dùng với arrow function
async function test() {
	const { users, notis } = await getUsersAndNotis();
  	// ...
}
Markup
Description

No description

To share this paste please copy this url and send to your friends
RAW Paste Data