One of the main reasons that you should use coroutines is to avoid callback hell.
This section will cover the following topics:
- What is a callback?
- Wrapping callbacks
One of the main reasons that you should use coroutines is to avoid callback hell.
This section will cover the following topics:
A callback is a pattern that is used to retrieve the results of an asynchronous task. This approach assumes that we pass a reference to a function that should be invoked when an asynchronous operation is done.
The loadImage function in the following example code uses a callback to return the result:
fun loadImage(callback: (Image) -> Unit) {
executor.submit...