https://kotlinlang.org logo
#coroutines
Title
# coroutines
f

Florian

09/02/2021, 10:04 AM
getLongestCompletedStreak
can take a while if the List is large. Will this setup do the list calculation on a background thread?
Copy code
private val taskStreaksMax =
        allTasksWithTaskStatisticsFlow.map { allTasksWithTaskStatistics ->
            allTasksWithTaskStatistics.map { taskWithTaskStatistics ->
                TaskStreak(
                    taskWithTaskStatistics.task.id,
                    taskWithTaskStatistics.taskStatistics.getLongestCompletedStreak()
                )
            }
        }.flowOn(defaultDispatcher)
Ok, I think I figured it out myself. I put a
Thread.sleep
into my sorting function and indeed, with the
flowOn
it doesn't freeze the screen, but without it it does.
o

Orhan Tozan

09/02/2021, 10:36 AM
What is
defaultDispatcher
?
f

Florian

09/02/2021, 10:42 AM
Dispatchers.Default
o

Orhan Tozan

09/02/2021, 10:49 AM
Ok, I assume the, getLongestCompletedStreak() function is suspending, and is the reason why it can take long?
f

Florian

09/02/2021, 11:09 AM
no, its no suspending
because it doesn't call any suspend functions
it's just searches through a list
2 Views