Callback methods can also be either synchronous or asynchronous and add a whole new dimension to how you can approach problems.
The way I think about callbacks is like this.
There’s two sides to a callback. One side defines what the callback should look like. In other words, what are the parameters and return type. This is the side that actually calls the callback method.
Then there’s the side that implements the callback method. The callback method needs to follow the guidelines set out by the side that’ll be making the call.
After all, if the method doesn’t match, then it can’t be called.
So whatever code is actually making the call gets to decide what the method will look like. The whole point of callbacks is to give control to the developer to do practically anything inside the callback. This means that you can normally think of a callback method as a method that you write but that you can give to some other code to actually run.
You have synchronous callbacks that never leave your thread. These are just like calling a method that then calls back one of your own methods.
And you have asynchronous callbacks that run in their own thread.