Is it better to use a kotlin coroutine or just to ...
# android
y
Is it better to use a kotlin coroutine or just to use the thread API in Android? I've been thinking of what is the "smart" way to prevent my grabcut() call from breaking the UI thread.
Still relevant to kotlin
d
I refactored my code from using threads to coroutines and pretty happy with it. Much lighter than threads.
y
@dgngulcan I didn't know there was a performance gain with coroutines.
k
they're similar to netty or the node.js event loop...they can run on the same thread
l
@yaakov There's not always a performance gain when using coroutines, but if you used to create one thread per operation (versus using executors), or used
Thread.sleep()
, and many more complex things with threads, it'll be much easier to avoid these pitfalls with coroutines thanks to coroutineContexts that encourage threads/executors/coroutineContexts reuse, non blocking
delay()
and much more non blocking stuff you can also write yourself as needed. Coroutines are a win for making performant readable code