-
-
Notifications
You must be signed in to change notification settings - Fork 51
Use Dispatchers.IO by default on multi-threaded platforms #905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use Dispatchers.IO by default on multi-threaded platforms #905
Conversation
…atcher to be configured in realtime and storage
Realtime/src/commonMain/kotlin/io/github/jan/supabase/realtime/Realtime.kt
Fixed
Show fixed
Hide fixed
I think it would be cleaner if |
We could do something similar to the serializers. So you can set a default dispatcher in the val supabase = createSupabaseClient(url, key) {
defaultCoroutineDispatcher = ... //By default set to the corresponding platform dispatcher
} .. maybe even Lines 6 to 16 in 4fd0c66
Then plugins which actually use a scope override this interface in their config, defaulting to null. And in the plugin implementation you have something like this: val dispatcher = config.ioDispatcher ?: supabase.defaultIoDispatcher //defaultIoDispatcher is obviously non-nullable
val scope = CoroutineScope(dispatcher...) For Auth, if we go with val dispatcher = config.ioDispatcher ?: config.coroutineDispatcher ?: supabase.defaultIoDispatcher
val scope = CoroutineScope(dispatcher...) But we can also leave the name and move up the |
@sproctor What do you think? I'd include this in the next release candidate. |
Sorry, I missed the notification on the initial comment. I'm not sure there's a ton of value to being able to set the dispatcher per module. It probably makes the most sense to just put the dispatcher in |
Yea then lets do that. |
Okay, I'll re-work this now |
Auth/src/commonMain/kotlin/io/github/jan/supabase/auth/AuthImpl.kt
Outdated
Show resolved
Hide resolved
Storage/src/commonMain/kotlin/io/github/jan/supabase/storage/Storage.kt
Outdated
Show resolved
Hide resolved
Storage/src/commonMain/kotlin/io/github/jan/supabase/storage/resumable/ResumableUpload.kt
Outdated
Show resolved
Hide resolved
Supabase/src/commonMain/kotlin/io/github/jan/supabase/SupabaseClientBuilder.kt
Outdated
Show resolved
Hide resolved
…ClientBuilder.kt Co-authored-by: Jan Tennert <[email protected]>
and allow dispatcher to be configured in realtime and storage
What kind of change does this PR introduce?
Bug fix/feature
What is the current behavior?
Dispatchers.Default
is used for all operations, but configurable inAuth
.What is the new behavior?
Dispatchers.IO
is used by default on JVM and K/N targets,Dispatchers.Default
is still used on JS and WASM targets. All invocations are configurable by an appropriate config.Additional context
Dispatchers.Default
is intended for CPU bound operations and is limited by the number of CPU cores. IO operations should useDispatchers.IO
instead.