Callback design pattern allows us to avoid "freezing" the rest of the application if a method takes too long to return. It is very useful if running computationally-expensive or time unpredictable methods. It does generally involve running in a separate thread/task.
- The solution involves creating
IXCallback
interface which contains method called whn the slow operation finishes running e.g.finish(
. - Add parameter of type XCallback to the slow operation
- Execute the body of the slow operation asynchronously (i.e. another thread/task, and call
finish(
to notify the caller