taer
05/19/2020, 4:32 PMflow.chunked()
var caughtException = false
val batches = batchResults(inputFlow, chunkSizePerMessage)
.map { createResults(it) }
.catch {
caughtException=true
emit(Results.TerminateWithError(it))
}
emitAll(batches)
if(!caughtException) {
emit(Results.SuccessfulFinish())
}
Ideally, the Successful finish would only be sent on no exceptions from the upstream flow. That var caughtException
seems ugly. Is there a cleaner way?elizarov
05/19/2020, 4:47 PMtaer
05/19/2020, 4:58 PMelizarov
05/19/2020, 5:00 PMflow
.onCompletion { emit(Results.SuccessfulFinish()) }
.catch { emit(Results.TerminateWithError(it) }
That's ittaer
05/19/2020, 5:03 PMelizarov
05/19/2020, 5:45 PM.onCompletion { if (it != null) emit(...) }
.onCompletion
taer
05/19/2020, 10:22 PM