Continuation Passing Style
The actual implementation of suspending computations is done using CPS. This paradigm is based on the premise of sending a continuation to a function that is invoked, so that upon completion, the function will invoke the continuation. You can think of continuations as callbacks: whenever a suspending computation invokes another, it will pass a continuation that should be called upon completion or error.
All the heavy lifting is done by the compiler, which transforms all the suspending computations so that they send and receive said continuations—as we will see, this means that the actual signatures of suspending functions are not the same as what we define. On top of that, the suspending computations are transformed ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access