https://kotlinlang.org logo
#announcements
Title
# announcements
j

Joey

12/10/2019, 5:36 AM
Hi guys, what is the best way to return a
List<String>
from a coroutine? My current code is this one but its kinda slow and affects my UI in android
Copy code
fun fetchUsers(): List<String> {
    val heartbeatApi = HeartbeatApi()
    val users = runBlocking {
        withContext(Dispatchers.Default) {heartbeatApi.fetchUsers() }
    }
    return users
}
i

itnoles

12/10/2019, 6:19 AM
You should not uses Default and runBlocking.
j

Joey

12/10/2019, 6:20 AM
What can you suggest? I needed something that has the capability of returning a
List<String
i

itnoles

12/10/2019, 6:22 AM
e

Eduardo Solano

12/11/2019, 9:59 AM
The network and data task run in Dispatchers.IO