reactormonk
02/27/2025, 5:16 PMsealed interface RemoteValidationResult {
data object Success : RemoteValidationResult
data class Failure(val errorResource: StringResource) : RemoteValidationResult
data class Pending(val loadingResource: StringResource) : RemoteValidationResult {
val next: Channel<RemoteValidationResult> = Channel(1, BufferOverflow.DROP_OLDEST)
}
}
And wiring it up as
val (result, flow) = validate(viewModelScope, text)
validationJob?.cancel()
validationJob = viewModelScope.launch {
if (result is RemoteValidationResult.Pending) {
launch {
result.next.consumeEach {
_state.transformIf<Loaded> {
copy(validationResult = it)
}
}
}
}
}
I'm wondering if there's a better way to approach thisBrill
02/27/2025, 5:28 PMreactormonk
02/27/2025, 5:31 PMreactormonk
02/27/2025, 5:31 PMFlow<RemoteValidationResult>
though and get rid of the Channel
🤔Brill
02/27/2025, 5:33 PMBrill
02/27/2025, 5:34 PMBrill
02/27/2025, 5:43 PMBrill
02/27/2025, 5:44 PM