A coroutine can provide a very high level of concurrency with very small overhead. Multiple threads can also provide parallelism but there is blocking and context switching. Coroutine suspends the thread and does not block it so that it can switch to another work.
Kotlin Extension Function?
Basically, Kotlin Extension Function provides a facility to add methods to class without inheriting a class or using any type of design pattern. The created extension functions are used as a regular function inside that class.
Why This "Android Coroutine Extensions"?
Kotlin's Coroutine Extension functions to fire
AppCompactActivity/Fragment/ViewModel which is tied to it's parent
CoroutineScope, so that If the parent is no loger exists, cancel any ongoing operation under the parent
- Lets assume that when an
Activityis started & you need to do some operation on the activity start. But user leave the screen and the ongoing Operation should be cancelled automatically.
APIrequest, assume you are calling an
ViewModelwith a different
Coroutine Scopeand leave the screen but the operation is still ongoing, because it was not instructed to cancel any ongoing operation when parent is no longer exist.
By using those extension functions you don't have to worry about the cancellation of ongoing operations according to the parent's
Let's a look at the available functions.
Follow Me on LinkedIn: