ghostty
michael@vegas : ~/writing · (main)
● connected
mdabout.md tsxprojects/ logexperience.log md2026-05-avoid-callback-hell.md jsoncontact.json
← :writing
2026-05 ⏱ 1 min

Avoid Callback Hell

When request 2 depends on request 1's data, .then chains pile up fast. The async/await refactor that makes JavaScript callback hell go away.

MP
Michael Pope Senior AI Engineer · Fractional CTO

Using promises is Javascript, when data resolved you can access the resolved values as an argument within a .then callback function. Imagine we are writing code where we need to make two separate API requests, and wait for both to resolve.

If request 2 depends on data from request 1, our code will look something like this:

!carbon (4).png

This can get messy very quickly, if the number of promises we need to resolve increases, so does the number of .then calls, resulting in an ugly chain of .then calls, also known as callback hell.

To escape callback hell, you can use Async/Await syntax in Javascript to ensure that promise data can be resolved before using it like this:

!carbon (5).png

— michael
Found this useful? Connect on LinkedIn or hire me for senior AI engineering / fractional CTO work.
NORMAL main ~/writing/2026-05-avoid-callback-hell.md markdown utf-8 1:1 Top