Scala Continuations Library
Callbacks are Continutations
The function argument to readFile is a continuation, in that readFile invokes it to continue program execution after it has done its job.
In order to rein in what can easily become callback hell, we use the continuations library.
Creating Functions That Take Continuations
If shift is called outside of a delimiting reset block, it can be used to create functions that themselves create continuations inside a reset block. It is important to note that shift's type is not just (((A => B) => C) => A), it is actually (((A => B) => C) => (A @cpsParam[B, C])). That annotation marks where CPS transformations are needed. Functions that call shift without reset have their return type "infected" with that annotation.
Inside a reset block, a value of A @cpsParam[B, C] seems to have a value of A, though really it's just pretending. The continuation that is needed to complete the computation has type A => B, so the code following a method that returns this type must return B. C is the "real" return type, and after CPS transformation the function call has the type C.
Now, the example, taken from the Scaladoc of the library
Here, ask will store the continuation into a map, and later some other code can retrieve that "session" and pass in the result of the query to the user. In this way, go can actually be using an asynchronous library while its code looks like normal imperative code.