Coroutines vs Promises: differences, benefits of o...
# android
n
Coroutines vs Promises: differences, benefits of one over the other, etc? I haven't touched Kotlin much yet, so I'm curious if there are some more experienced voices who could weigh in...
u
ninjasudo: Look at #coroutines channel In short, coroutines are like light weight threads. You can launch 100000 coroutines at once and don't get out of memory error. How you will use it depends on framework you chose. So, promises, rx, forkjoin, all can be wrapped by coroutines. Also, Kotlin has first class syntax for coroutines. You can write sequential nonblocking code as it was synchronous code, without nesting tons of callbacks. https://kotlinlang.org/docs/reference/coroutines.html#experimental-status-of-coroutines https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md
n
Thanks for the synopsis, I'll certainly look into it more. We're about to do a 3 day hackathon writing an app from scratch in Kotlin. I'm already used to Promises and asynchronous code flows. It's good to hear this is first class in Kotlin.
u
b
@umar So it's coroutines < threads < processes?
u
I don't understand what you mean. Can you explain?
b
Coroutines are very portable. Threads have a little overhead, and processes a lot of overhead
u
Yes, they have very very small overhead
Understood you