Skip to content

refactor(deps): inject CoroutineDispatchers#4170

Merged
jamesarich merged 1 commit into
mainfrom
refactor/dispatchers
Jan 8, 2026
Merged

refactor(deps): inject CoroutineDispatchers#4170
jamesarich merged 1 commit into
mainfrom
refactor/dispatchers

Conversation

@jamesarich

Copy link
Copy Markdown
Collaborator

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.

inspired by #4125 , but done with a bit more caution

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>
@github-actions github-actions Bot added the refactor no functional changes label Jan 8, 2026
@codecov

codecov Bot commented Jan 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (6818546) to head (f2fd2f0).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@jamesarich jamesarich added this pull request to the merge queue Jan 8, 2026
Merged via the queue into main with commit 7744a42 Jan 8, 2026
8 checks passed
@jamesarich jamesarich deleted the refactor/dispatchers branch January 8, 2026 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor no functional changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant