Definition
An async callback is a function that a program hands to another component — typically a library, a runtime, or a network client — with the contract that the receiving component will invoke it later, when some external event happens. The caller does not block waiting for the result; it returns immediately to its event loop or to the next instruction, and the callback fires at whatever later point the awaited thing is ready.
The pattern is the foundational building block of event-driven programming and predates more recent ergonomic wrappers (Promises, Futures, async/await). Under almost every modern non-blocking abstraction — Node.js, asyncio, Twisted, libuv, browser fetch — there is still a callback being scheduled and dispatched by an event loop. Understanding the raw callback model is what makes the wrappers comprehensible when something goes wrong.
Why it matters
How it works
The mechanism rests on three pieces. An event source — a socket, a timer, a subscription — knows when something has happened and holds a reference to the callback to invoke when it does. An event loop owns the single thread of execution, drains the pending-callbacks queue, and pumps them one at a time. The callback itself is a closure that captures whatever state from the registering context it needs to act on when it fires. Together these let a program juggle thousands of concurrent in-flight operations on a single OS thread, because each one is idle most of the time and the loop is the only active code.
The standard failure modes are pedagogically famous. Callback hell is the pyramid of nested anonymous functions that emerges when one async step depends on another, which depends on another. Error handling is harder than in synchronous code because exceptions thrown inside a callback are caught by the loop, not by the caller that registered it — every callback must handle its own errors or pass them explicitly to a known handler. Concurrent state mutation looks safe because there is only one thread, but is unsafe in slow-motion: between a callback registering and firing, the world it captured in its closure may have changed beneath it. The discipline of writing correct callback code is the discipline of making every fire-time assumption explicit.