I see by default, it takes the line commented on plus four lines from the top 🤔 I'll keep that in mind for next time
For concurrency safety, I suggest the following approach that is more idiomatic and explicit with the intent:
Be careful when combining the elvis operator (?:
) with the run
scoping function - it is not the same as a null-check via an if(x == null)
or a let
call (x?.let {}
).
What ProcessingStatus
states are not being handled? Enums can be exhausted in a when
statement
I suggest you don't model your screen state this way. It works on a small scale but quickly grows to become unmanageable later on. Prefer a single data class
with all the state needed.
ViewModels generally expose a StateFlow that emits changes, which the UI then reacts to (works well with Compose, but can also work with Fragments and Views). A single state is generally exposed to observe per screen. The ViewModel has separate states internally which then gets combined into a single state for simplicity for the view
With Kotlin's suspending functions, you can write async code in a sequential matter. Handler
is less commonly used since the introduction of Kotlin coroutines. Here is a rough equivalent using a suspending function: