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

jw

07/01/2020, 5:18 PM
they are synchronous so use
withContext
👍 3
m

Mustafa Ozhan

07/19/2022, 9:13 AM
@jw what about when we request as flow ? will
Copy code
fun getActiveCurrencies() = currencyQueries
        .getActiveCurrencies()
        .asFlow()
        .flowOn(ioDispatcher)
        .mapToList(ioDispatcher)
be enough ? or should we still call with
withContext
like this?
Copy code
suspend fun getActiveCurrencies() = withContext(ioDispatcher) {
        currencyQueries
            .getActiveCurrencies()
            .asFlow()
            .flowOn(ioDispatcher)
            .mapToList(ioDispatcher)
    }
j

jw

07/19/2022, 12:58 PM
Remove flowOn
Also withContext
Also suspend
m

Mustafa Ozhan

08/07/2022, 10:54 PM
Thanks a lot for the answers! Removing
withContext
and
suspend
makes perfect sense, but I confused about removing the
flowOn(ioDispatcher)
is SQLDelight emitting value changes on IO thread ?
j

jw

08/07/2022, 10:56 PM
You pass a dispatcher to the map function which is where the query is executed
m

Mustafa Ozhan

08/07/2022, 11:00 PM
Ohh right, the rest actually doesn’t require the context in terms of the querying 👍 Thanks a lot!
6 Views