Removed all instances of withContext. withContext requires the caller to know something about the execution of the enclosed method(s) (e.g. it is cpu or disk bound). In this case, these calls are redundant because the only I/O bound operations are handled by Room, which will already move those operations onto the I/O thread, so we don't need to be concerned with it.
Removed the completeTask(task: Task) and activateTask(task: Task) methods in favour of using the existing completeTask(taskId: String) and activateTask(taskId: String). This creates a smaller API surface which is more loosely coupled.
Refactored Task to be immutable. Having a mutable model is an anti-pattern as it allows callers to modify the model, which violates SSOT.
Here's what I've done and why:
withContext
.withContext
requires the caller to know something about the execution of the enclosed method(s) (e.g. it is cpu or disk bound). In this case, these calls are redundant because the only I/O bound operations are handled by Room, which will already move those operations onto the I/O thread, so we don't need to be concerned with it.completeTask(task: Task)
andactivateTask(task: Task)
methods in favour of using the existingcompleteTask(taskId: String)
andactivateTask(taskId: String)
. This creates a smaller API surface which is more loosely coupled.Task
to be immutable. Having a mutable model is an anti-pattern as it allows callers to modify the model, which violates SSOT.