Callback hell makes code impossible to follow and debug.
// dirty — pyramid of doom
function buildPipeline(userData, ordersData, productsData) {
return new Promise((resolve) => {
fakeUser(userData, (user) => {
fakeOrders(ordersData, (orders) => {
fakeProducts(productsData, (products) => {
resolve({ user, orders, products });
});
});
});
});
}Refactor `solve(userData, ordersData, productsData)` using async/await so the function is flat and readable.
The fake fetchers are already provided as Promises — no callbacks.
solve({ id: 'u1', name: 'Alice' }, [{ id: 'o1' }], [{ id: 'p1' }]) → Promise<{ user, orders, products }>
Sample tests