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 PMelizarov
05/19/2020, 4:48 PMtaer
05/19/2020, 4:58 PMtaer
05/19/2020, 4:59 PMelizarov
05/19/2020, 5:00 PMelizarov
05/19/2020, 5:02 PMflow
.onCompletion { emit(Results.SuccessfulFinish()) }
.catch { emit(Results.TerminateWithError(it) }
That's ittaer
05/19/2020, 5:03 PMtaer
05/19/2020, 5:03 PMtaer
05/19/2020, 5:06 PMtaer
05/19/2020, 5:07 PMtaer
05/19/2020, 5:11 PMtaer
05/19/2020, 5:11 PMelizarov
05/19/2020, 5:45 PM.onCompletion { if (it != null) emit(...) }
.elizarov
05/19/2020, 5:45 PMonCompletion
taer
05/19/2020, 10:22 PM