Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
mobile ruleP1stack specificStack: kotlin
kotlincoroutinesdispatcherstestabilitydi
Inject coroutine dispatchers instead of referencing them directly
Depend on an injected dispatcher (from a DispatcherModule) rather than hardcoding Dispatchers.IO/Default, so coroutines are testable with a test dispatcher.
PR: profico-mining-2026-06Created: Jul 26, 2026
Bad example
Old codekotlin
| 1 | viewModelScope.launch(Dispatchers.IO) { repo.load() } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codekotlin
| 1 | class VM(private val io: CoroutineDispatcher) { fun load() = viewModelScope.launch(io) { repo.load() } } |
Explanation (EN)
Objašnjenje (HR)