Skip to content

Instantly share code, notes, and snippets.

@iMichaelOwolabi
Created February 7, 2022 08:30
Show Gist options
  • Save iMichaelOwolabi/089f962ab6b54267a42c397c95863541 to your computer and use it in GitHub Desktop.
Save iMichaelOwolabi/089f962ab6b54267a42c397c95863541 to your computer and use it in GitHub Desktop.
Blocking dependent promise implementation sample
// Application logic that get employee records alongside their individual next of kin data
const getAllEmployeeInformation = async () => {
// Start recording the execution time of the following code.
console.time('bad await')
const allEmployees = await getAllEmployees(); // Get all employee from the DB
const allEmployeeRecords = [];
// Map individual employee record with their next of kin data and return the mapped data
for (const employee of allEmployees) {
const nextOfKin = await getEmployeeNextOfKin(employee.id);
allEmployeeRecords.push({ ...employee, nextOfKin });
}
console.log(allEmployeeRecords);
// Stop recording the execution time and log the elapsed time to the console.
console.timeEnd('bad await');
return allEmployeeRecords;
}
getAllEmployeeInformation();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment