https://kotlinlang.org logo
#android
Title
# android
y

yaakov

01/05/2018, 5:50 PM
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

dgngulcan

01/05/2018, 6:02 PM
I refactored my code from using threads to coroutines and pretty happy with it. Much lighter than threads.
y

yaakov

01/05/2018, 6:44 PM
@dgngulcan I didn't know there was a performance gain with coroutines.
k

kenkyee

01/05/2018, 6:53 PM
they're similar to netty or the node.js event loop...they can run on the same thread
l

louiscad

01/05/2018, 6:56 PM
@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