Did you know that coroutines were invented about 50 years ago? A coroutine is a function that can not only return but also suspend its execution somewhere in the middle, it can be later resumed to continue the execution.Imagine, in Java or JVM, a function that can suspend its execution and free the call stack. Does it give power? It does! It simplifies the callback hell of your non-blocking application. A for-loop is now enough to implement an iterator, that lazily computes the elements. In Kotlin, “suspend” functions can suspend and are called coroutines. And it is the power. We’ll use it as the remedy for the callback hell problem of our non-blocking applications. Of course, we’ll build an iterator with for-loop and yield-return. Coroutines help to offload the work from a UI thread of a desktop or Android applications easily. The main giveaway is you’ll learn how to use Kotlin suspend functions and coroutines to simplify your daily tasks.
comments powered by Disqus