In my program, I have a long-running function from which I would like to interact with the user for various reasons:
- Giving status updates (“Downloading file
- Displaying warnings (“File upload failed; will retry later”)
- Asking for input (“Please enter your google drive password”)
The problem is, of course, that this function doesn’t know how it should interact with the user. For example, it would be nonsensical to display messages on stdout in a GUI program.
In case of errors, the solution is obvious – just throw an exception that’ll be caught in the user interface layer. Errors are easy because the service layer’s job is done as soon as the exception is thrown. But what about things like warnings and input? How do I bridge the gap between the service layer and the user?