Last updated 305 days ago by Rohit Surwasekotlin
The common terms used in Coroutines. Knowing these terms in advance will ease your learning process.
This article is a brief summary of official Kotlin doc and a few other resources that I have gone through over time during my learning. This is my attempt to simplify common terms used in the context of coroutines and give you the taste of the power, coroutine gives you which would inspire you to jump in the world of coroutines as asynchronous or non-blocking programming is a new reality.
Developing Apps using Kotlin is really fun. Code less, perform better suits very well for Kotlin. And with coroutines, it becomes sweeter. Coroutines are now stable and can be used within an early-access-preview version of Kotlin v1.3. So, it is the best time to learn about coroutines and start using it in your Android projects.
“A coroutine is an instance of suspendable computation, conceptually similar to a thread, in the sense that it takes a block of code to run and has a similar life-cycle, it is created and started, but it is not bound to any particular thread. It may suspend its execution in one thread and resume in another one. Moreover, like a future or promise, it may complete with some result or exception.”
Coroutines are lightweight threads and they are so cheap to create which open the doors to asynchronous programming for developers. This means we can call more than one functions asynchronously and get the result in a shorter duration in very effective way. Now imagine how faster our validations would be as we can call them asynchronously. All those things (API calls, Database access…) which need a background thread to process are just a few lines away than creating separate worker threads for it and then managing it. And making coroutines life-cycle aware is so simple.