Skip to content

Conversation

@SimonMarquis
Copy link
Contributor

Switching to IO Dispatcher from the ViewModel classes instead of where the blocking call happens breaks the "main-safe" convention of Kotlin coroutines as well as the dispatching responsibility.

I migrated the suspending call down to where it is actually needed: in the LocalFileProviderImpl.

Also cleanup the unnecessary manual buffering (for copying files/streams) as Kotlin's InputStream.copyTo() already does it with a default 8kiB buffer.

And to keep the cancelable tasks (that was previously canceling the global IO dispatcher entirely), I've added two Job instances in the CreationViewModel that can be canceled as needed.

Switching to IO Dispatcher from the ViewModel classes instead of where the blocking call happens breaks the "main-safe" convention of Kotlin coroutines as well as the dispatching responsibility.

I migrated the suspending call down to where it is actually needed: in the `LocalFileProviderImpl`.

Also cleanup the unnecessary manual buffering (for copying files/streams) as Kotlin's `InputStream.copyTo()` already does it with a default 8kiB buffer.

And to keep the cancelable tasks (that was previously canceling the global IO dispatcher entirely), I've added two `Job` instances in the `CreationViewModel` that can be canceled as needed.
@riggaroo riggaroo merged commit 9323f40 into android:main Jun 9, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants