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
IXCallbackinterface which contains method called whn the slow operation finishes running e.g.
- 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