Is there any way to have a subroutine send data back while still processing? For instance (this example used simply to illustrate) – a subroutine reads a file. While it is reading through the file, if some condition is met, then “return” that line and keep processing. I know there are those that will answer – why would you want to do that? and why don’t you just …?, but I really would like to know if this is possible.
Share
A common way to implement this type of functionality is with a callback function:
or without even naming the callback: