F
F
foonfyrick2021-03-28 09:24:20
Kotlin
foonfyrick, 2021-03-28 09:24:20

How to choose whether to create a thread or a coroutine?

When I want to execute some code without slowing down the main thread, how do I choose whether to create a thread or a coroutine?
What features should the code have so that I can confidently say that it should be in a coroutine, and not in another thread, and vice versa?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-03-28
@foonfyrick

You never need to create a flow with your hands. As a last resort, use a thread pool.
If you use coroutines, use coroutines. With the right controller. In your case, running on Dispatchers.Default will do . There's just a thread pool on the JVM under the hood.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question