Callback hell makes code impossible to follow and debug.
// dirty — pyramid of doom
function buildPipeline(
userData: { id: string; name: string },
ordersData: Array<{ id: string }>,
productsData: unknown[],
) {
return new Promise((resolve) => {
fakeUser(userData, (user: unknown) => {
fakeOrders(ordersData, (orders: unknown) => {
fakeProducts(productsData, (products: unknown) => {
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