Conclusion
That’s it! You’ve just implemented your first coroutine. You’ve learned:
- How to start a coroutine in an Android application.
- The difference between the
runBlockingand thelaunchcoroutine builders and between blocking and suspending code execution. - How to cancel coroutines. Remember that a coroutine cancellation consists of throwing an exception. You must not catch the exception without re-throwing it later, because the coroutine in question could keep running indefinitely.
In the next lesson, you’ll learn about coroutine scopes and dispatchers.