Android Coroutine Extensions

Senior Android Engineer from Bangladesh. Love to contribute in Open-Source. Indie Music Producer.
Search for a command to run...

Senior Android Engineer from Bangladesh. Love to contribute in Open-Source. Indie Music Producer.
No comments yet. Be the first to comment.
A practical guide to choosing the right coroutine primitive for your Android/Kotlin projects

This guide explains what Channels are, when to use them, how to use them correctly, and when NOT to use them β in simple, professional language. 1. What problem do Channels solve? In Kotlin coroutines, you often have multiple coroutines running at t...

Learn how to build preview-safe ViewModels in Jetpack Compose using Hilt.

HandlerInterceptor vs Filter in Spring Boot: A Practical Guide with JNDI Injection Prevention

Simple In-Memory Caching: A Tiny Trick with Massive Impact

If get to know something new by reading my articles, don't forget to endorse me on LinkedIn
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.
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.
Kotlin's Coroutine Extension functions to fire CoroutineScope from 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 CoroutineScope.
Basic Usages:
Lets assume that when an Activity is started & you need to do some operation on the activity start. But user leave the screen and the ongoing Operation should be cancelled automatically.
For API request, assume you are calling an API from your ViewModel with a different Coroutine Scope and 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 LifeCycle.
Let's a look at the available functions.
Follow Me on LinkedIn: