fjoglar
10/20/2020, 11:31 AMActivity
, I'm getting:
java.lang.IllegalStateException: ReceiveChannel.consumeAsFlow can be collected just once
The code I'm executing from is this:
private fun getCustomer() = lifecycleScope.launch {
isLoading = true
// Get the user's customer code.
GetUserDetailsUseCase().getCustomer().collect { result ->
when (result) {
is Result.Success -> uploadDocument(result.data)
is Result.Error -> showPopup(result.errorMessageResId)
}
}
}
private fun uploadDocument(customer: Customer) = lifecycleScope.launch {
this@SignUpDocumentValidationActivity.customer = customer
// Upload document and get URL.
val filename = "${System.currentTimeMillis()}${customer.code}"
when (val uploadResult = UploadImageUseCase().uploadImage(
scaleImage(),
filename
)) {
is Result.Success -> {
Logger.i(TAG, "Image $filename.jpg uploaded successfully.")
sendDocumentAndContinue(uploadResult.data)
}
is Result.Error -> showPopup(uploadResult.errorMessageResId)
}
}
private fun sendDocumentAndContinue(documentUrl: String) = lifecycleScope.launch {
// Send document to backend
UpdateDocumentUseCase().updateDocument(
customer!!,
DocumentType.values()[currentStep],
documentUrl
).collect { result ->
when (result) {
is Result.Success -> {
deleteImage()
isLoading = false
nextStep()
}
is Result.Error -> showPopup(result.errorMessageResId)
}
}
}
How can I get rid of this issue and call the two collect() methods secuentially?
Thanks!travis
10/20/2020, 5:05 PMreceiveAsFlow
?