January 2020
Intermediate to advanced
470 pages
11h 13m
English
The preceding code, in which you call a function but also pass another function that is to be executed when the input/output operation is finished, can be considered a case of continuation passing style (CPS). What is this technique of coding? One way of looking at it is by thinking about the question: how would you program if using the return statement was forbidden?
At first glance, this may appear to be an impossible situation. We can get out of our fix, however, by passing a callback to the called function, so that when that procedure is ready to return to the caller, instead of actually returning, it invokes the passed callback. By doing this, the callback provides the called function with the way to continue ...