# Why we need coroutine suspend modifier?

**URL:** <https://discuss.kotlinlang.org/t/why-we-need-coroutine-suspend-modifier/8036>\
**Category:** Language Design\
**Created:** [June 5, 2018, 9:02pm UTC](https://discuss.kotlinlang.org/t/why-we-need-coroutine-suspend-modifier/8036 "2018-06-05T21:02:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ondrejvelisek](https://avatars.discourse-cdn.com/v4/letter/o/8c91f0/32.png) [@ondrejvelisek](https://discuss.kotlinlang.org/u/ondrejvelisek)\
**Post date:** [June 5, 2018, 9:02pm UTC](https://discuss.kotlinlang.org/t/why-we-need-coroutine-suspend-modifier/8036/1 "2018-06-05T21:02:00Z")

</div>

Maybe it sounds stupid. But still I couldnt find any answer so far. I just jumped into coroutines few weeks ago and it is changing my point of view on async progrmaming. Thanks for that! To the point:

I wanted to test what I learned about coroutines. So I just took small android app and I rewrote some interfaces to use coroutines. Basically just add suspend modifier and use retrofit-coroutine library. Everywhere where I called such interface I used async builder and it worked.

Than I’ve wrapped location service and storage service. At one point I was thinking it is not probably a good way to have async everywhere, it looked more like Promise pattern than coroutines, so I just started to adding suspending functions to higher and higher interfaces and I ended up with one big launch builder around whole activity onCreate method and bunch of suspend function.

At that point I’ve started to asking myself why I need to mark functions as suspendable? As a user of an interface a use them in a same manner. No difference. Only If I want them run asynchronously i can use async. But I can have suspend modifier on actually non suspending function at all. Why not all the functions in kotlin are suspendable by default without modifier? Woudn’t it be easier for developers? Less code, less builders? Is it due to readability? Or some statical analysis? Performance? Or is there some “real” reason?

Hope it all make sense. Thank you for answer!

Ondrej

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [June 5, 2018, 11:29pm UTC](https://discuss.kotlinlang.org/t/why-we-need-coroutine-suspend-modifier/8036/2 "2018-06-05T23:29:39Z")

</div>

Yes there is a reason 😉 You might not see it but the suspend keyword adds an additional parameter to your function. If you go and take a look at the bytecode or decompile it back to java you see that

```kotlin
suspend fun test() {}

```

actually is

```kotlin
fun test(continuation: Continuation) {}

```

This hidden parameter is used to make coroutines work. If you want to know how it works exactly you have to ask someone more knowledgable than me, but this is the reason why you have to use the `suspend` modifier.

---

<div class="post-metadata">

**Author:** ![ondrejvelisek](https://avatars.discourse-cdn.com/v4/letter/o/8c91f0/32.png) [@ondrejvelisek](https://discuss.kotlinlang.org/u/ondrejvelisek)\
**Post date:** [June 6, 2018, 5:34am UTC](https://discuss.kotlinlang.org/t/why-we-need-coroutine-suspend-modifier/8036/3 "2018-06-06T05:34:12Z")

</div>

Thank you for answer. I see. But why not to add such parameter to all of the functions?

---

<div class="post-metadata">

**Author:** ![darksnake](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/darksnake/32/2479_2.png) [@darksnake](https://discuss.kotlinlang.org/u/darksnake)\
**Post date:** [June 6, 2018, 5:39am UTC](https://discuss.kotlinlang.org/t/why-we-need-coroutine-suspend-modifier/8036/4 "2018-06-06T05:39:48Z")

</div>

For example, it will completely break java compatibility.  
For now, calling suspended function from java is a pain. We do not want that for all functions. Also it is very useful to understand by looking on keywords, weather we are looking for the common code that could be run, say, from the UI thread, or suspended function that is long running and must be invoked on another thread.

---

<div class="post-metadata">

**Author:** ![ondrejvelisek](https://avatars.discourse-cdn.com/v4/letter/o/8c91f0/32.png) [@ondrejvelisek](https://discuss.kotlinlang.org/u/ondrejvelisek)\
**Post date:** [June 6, 2018, 5:47am UTC](https://discuss.kotlinlang.org/t/why-we-need-coroutine-suspend-modifier/8036/5 "2018-06-06T05:47:54Z")

</div>

Great point! Thank you. Didn’t think about compatibility.
