refactor(deps): inject CoroutineDispatchers#4170
Merged
Merged
Conversation
This commit refactors the codebase to use an injected `CoroutineDispatchers` provider instead of hardcoding `Dispatchers.IO` or `Dispatchers.Default`. This improves testability by allowing dispatchers to be replaced with test dispatchers in unit tests. It also removes a `runBlocking` call in `ContactsViewModel` for better performance and responsiveness. Additionally, `Thread.sleep` has been replaced with `delay` to make the function suspendable. Key changes: - Introduced `CoroutineDispatchers` dependency in various data sources, repositories, and services. - Replaced direct calls to `Dispatchers.IO` and `Dispatchers.Default` with the injected `dispatchers` instance. - Added the `core:di` module as a dependency to `core:database` and `core:network`. - Removed `runBlocking` from `ContactsViewModel` when fetching message counts. - Replaced `Thread.sleep` with `delay` in `ServiceClient`. - Simplified the `formatAgo` utility to use `DateUtils.SECOND_IN_MILLIS` for more accurate relative time formatting, removing the special "now" case. Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4170 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 2 2
Lines 19 19
Branches 7 7
=====================================
Misses 19 19 ☔ View full report in Codecov by Sentry. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This commit refactors the codebase to use an injected
CoroutineDispatchersprovider instead of hardcodingDispatchers.IOorDispatchers.Default. This improves testability by allowing dispatchers to be replaced with test dispatchers in unit tests.It also removes a
runBlockingcall inContactsViewModelfor better performance and responsiveness. Additionally,Thread.sleephas been replaced withdelayto make the function suspendable.Key changes:
CoroutineDispatchersdependency in various data sources, repositories, and services.Dispatchers.IOandDispatchers.Defaultwith the injecteddispatchersinstance.core:dimodule as a dependency tocore:databaseandcore:network.runBlockingfromContactsViewModelwhen fetching message counts.Thread.sleepwithdelayinServiceClient.formatAgoutility to useDateUtils.SECOND_IN_MILLISfor more accurate relative time formatting, removing the special "now" case.inspired by #4125 , but done with a bit more caution