-
Notifications
You must be signed in to change notification settings - Fork 36
feat(ui): add launchIO helper to BaseViewModel for background operations #129
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 146
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 97
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 950
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 97
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 916
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 3685
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 510
🏁 Script executed:
# Examine DispatchManagerImpl to understand the dispatcher abstraction cat -n core-base/common/src/nonAndroidMain/kotlin/template/core/base/common/manager/DispatchManagerImpl.ktRepository: openMF/kmp-project-template
Length of output: 1383
🏁 Script executed:
# Check androidMain version cat -n core-base/common/src/androidMain/kotlin/template/core/base/common/manager/DispatchManagerImpl.ktRepository: openMF/kmp-project-template
Length of output: 1378
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 53
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 2401
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 1380
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 1032
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 53
🏁 Script executed:
Repository: openMF/kmp-project-template
Length of output: 53
launchIOname and KDoc are semantically incorrect forDispatchers.Default.Dispatchers.Defaultis a CPU-bound dispatcher (thread pool capped at CPU cores).Dispatchers.IO— available on JVM and Native targets — is the dispatcher designed for offloading blocking I/O-intensive operations. The codebase already has aDispatcherManagerabstraction that handles this: on Android,manager.defaultmaps toDispatchers.IO; on non-Android platforms, it falls back toDispatchers.Defaultfor compatibility.Two concrete problems with the current implementation:
Name
launchIOimplies IO-dispatcher semantics. Developers reading call sites will expect optimal behavior for I/O operations (on Android, the 64-thread IO pool); instead they get a pool capped at CPU cores. A name likelaunchBackgroundorlaunchOnDefaultwould be accurate.KDoc is inaccurate and dangerous. The comment reads "for network or database operations" and "I/O-bound work" — the exact description of
Dispatchers.IO. If a developer follows the KDoc literally and performs blocking I/O (e.g., legacy JDBC,File.readText) insidelaunchIO,Dispatchers.Default's small thread pool will be exhausted, starving all coroutines in the app.Additionally, the function bypasses the existing
DispatcherManagerabstraction, using rawDispatchers.Defaultinstead of injecting the platform-appropriate dispatcher.✏️ Suggested rename and corrected KDoc
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@therajanmaurya This review is correct, and ViewModelScope already bounded to the lifecycle of the app with the required dispatcher, and we won't need this anti-pattern, and hardcoding the dispatcher will cause the codebase to test as while testing we need to swap out with unconfined dispather.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.