I am very confused about the difference between co...
# coroutines
b
I am very confused about the difference between coroutines and suspend functions, and this is what I think about them. Am I correct? Coroutine is like Threads but lightweight, it basically creates a new lightweight job or task on the other hand, the suspend function is like a function which is signalling that - "O My Coroutine, I might have some task which might take longer so you can run me on your own thread" hence suspend/pause the Coroutines execution. In Short, a Coroutine is just like a bus and suspend functions are like stops.
k
A coroutine is the thing that runs suspend functions. Suspend functions signal to the coroutine they’re running in that they are suspended. Your bus stop analogy is fairly good.
b
Why do we even need a suspend function why not just the whole function be suspended. I mean whatever code we write inside Coroutines why not consider it suspended by default why introduce a new keyword?
🧵 1
k
Because it’s good to have a distinction between functions which will be fast and functions which might take a long time
@elizarov has a talk about this on youtube that touches on this in relation to loom

https://www.youtube.com/watch?v=zluKcazgkV4

b
Thanks, @kevin.cianfarini! I'll watch it right away.