Skip to content

Instantly share code, notes, and snippets.

@rowlandekemezie
Created April 6, 2020 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowlandekemezie/40ecf5ff231ab3c656153185dba96f87 to your computer and use it in GitHub Desktop.
Save rowlandekemezie/40ecf5ff231ab3c656153185dba96f87 to your computer and use it in GitHub Desktop.
// Current. The request is synchronous because the former needs to finish before the later
const earning = await fetchLastMonthEarning(teacherInfo.teacher.teacherId, startDate, endDate);
const teachingHours = await fetchTeachingHours(teacherInfo.teacher.teacherId);
// Refactored. Ensures the request is run concurrently
const [ earning, teachingHours ]= await Promise.all([
fetchLastMonthEarning(teacherInfo.teacher.teacherId, startDate, endDate),
fetchTeachingHours(teacherInfo.teacher.teacherId)
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment