

Coroutines share the stack due to support for suspension. It means coroutine suspend execution by returning to the caller and the data that is required to resume execution is stored separately from the stack. It means when one routine is executing, the other routine will not interfere with 1st coroutine w.r.t to memory, cpu ,any resource by suspending itself i.e without blocking.Ĭoroutines don't have a dedicated stack. i.e routines which cooperate with each other. Personally, I was wondering what would be the application of context receivers in one of the codes I’ve already written or seen, and this article is meant to help all those who can find themselves in my shoes.Co-Routines means cooperative routines. In Kotlin, you can define such a context-restricted declaration using a member extension function interface BoxScope ConclusionĬontext receivers cover various use cases, there are several articles that give prerequisites with basic examples to help you understand this concept and its use cases. We have modifiers that can only be accessed inside a certain scope, like a type of Modifier.align(alignment: Alignment) which can only be used inside a BoxScope, the Modifier.align(alignment: Alignment.Horizontal) for ColumnScope,etc. Let’s take an example of Jetpack Compose.


This article aims to demonstrate one of the many use cases and problems that Kotlin context receivers have come to solve by using a real-life case. We can use context receivers to express constraints. Sometimes in our code, we want to use something only in a certain scope, without which it won’t work properly.
