Created
February 7, 2022 08:30
-
-
Save iMichaelOwolabi/089f962ab6b54267a42c397c95863541 to your computer and use it in GitHub Desktop.
Blocking dependent promise implementation sample
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
// 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