Image for Continuation Passing Style

Continuation Passing Style

Continuation Passing Style (CPS) is a programming technique where functions don’t directly return results. Instead, they receive an extra function—called a "continuation"—that specifies what to do next. After completing their task, functions call this continuation with their result. This approach makes control flow explicit, allowing for advanced features like asynchronous operations and easier error handling. Think of CPS as passing a "next step" function along with your main task, so when the task finishes, it knows exactly how to proceed, providing greater flexibility and control over program execution.