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

jw

04/07/2021, 2:11 PM
they must not be run on main. all of the APIs should be using
Default
as, well, a default.
d

Daniele B

04/07/2021, 2:15 PM
I did not encounter problems running them on Dispatchers.Main, so I was assuming simple queries could be run there.
k

Kris Wong

04/07/2021, 2:17 PM
as a best practice we do not perform any file or network IO on the main thread
j

jw

04/07/2021, 2:17 PM
if you're using Android then turn on strict mode and your app will kindly crash when you do this
d

Daniele B

04/07/2021, 2:17 PM
Is there any way to setup SqlDelight to automatically generate functions that run on WithContext(Dispatchers.Default) ?
j

jw

04/07/2021, 2:17 PM
no
if you use the built-in Flow extension that is the default behavior
👍 1
d

Daniele B

04/07/2021, 2:33 PM
do you also use Dispatchers.Default for reading a value from MultiplatformSettings?
k

kevin.cianfarini

04/07/2021, 2:34 PM
You probably want some sort of abstraction (like a repository?) that ensures all network and database operations are main safe. Retrofit, for example, is main safe, however SQLDelight doesn’t expose first class
suspend
functions.
👍 1
j

jw

04/07/2021, 2:35 PM
i don't know what MultiplatformSettings is
k

kpgalligan

04/07/2021, 2:50 PM
MultiplatformSettings would best be answered by @russhwolf I see there's a coroutines extension I've never played with, so the answer I was typing was wrong.
r

russhwolf

04/07/2021, 3:09 PM
Settings doesn't do anything with dispatchers normally and lets the platforms APIs it delegates to handle threading (or not) when they write to disk. If you use the new experimental coroutines extensions and convert your
Settings
to a
SuspendSettings
(or
ObservableSettings
to
FlowSettings
), then you can pass a dispatcher for it to run on which will default to
Dispatchers.Default
. Most people probably aren't doing that though because those interfaces really only exist to make it easier to interop with androidx.datastore which nobody is using yet
2 Views