dave08
09/19/2019, 1:44 PMDominaezzz
09/19/2019, 2:01 PMFlow
simply cannot do this. How does the caller of emit
know to skip an element. The exception will have to be caught and skipped by the same emitter that threw it. It can't be done upstream or downstream.Vsevolod Tolstopyatov [JB]
09/19/2019, 2:23 PMval flow = flow {
emit(1)
emit(2)
}.map { value ->
if (value == 1) throw IllegalStateException()
else value
}.ignoreIllegalStateExceptionOperator()
.collect { value ->
println(value)
} // prints "2"
streetsofboston
09/19/2019, 2:28 PMdave08
09/19/2019, 3:17 PMVsevolod Tolstopyatov [JB]
09/22/2019, 12:02 PMignoreIllegalStateExceptionOperator
is the first operator in your chain, then you can just catch exceptions you don’t want to propagate to the upsteam.dave08
09/24/2019, 11:01 AMSecurityException
if the user is not registered (there's no other way to check in this api... 😞 ), So a registration function must be called and the flow should keep on receiving click events (or be able to retry...) after that... Not sure if that's feasable... should I still open the issue @Vsevolod Tolstopyatov [JB]?Vsevolod Tolstopyatov [JB]
09/24/2019, 2:34 PMretry
operator after an operation (map { transfromThatMayThrow() }.retry { /* your logic here */ }.collect()
), but it’s hard to tell without a detailed understanding of your use casedave08
09/25/2019, 1:53 PMstreetsofboston
09/25/2019, 1:59 PMval data = flow<Int> { try { .... } catch (e: Throwable) { ... } }
), but for an existing one, I see no good way of forcing that Flow to continue, much like Rx-Observables or Flowables.
You could restart a Flow, though, by re-subscribing/re-collecting it again on an exception.dave08
09/25/2019, 3:11 PMstreetsofboston
09/25/2019, 3:12 PMDominaezzz
09/25/2019, 3:12 PMFlow<Result<T>>
might be an option.dave08
09/25/2019, 3:12 PMstreetsofboston
09/25/2019, 3:13 PMdave08
09/25/2019, 3:13 PMstreetsofboston
09/25/2019, 3:14 PMDominaezzz
09/25/2019, 3:15 PMretry
operator.dave08
09/25/2019, 3:17 PMstreetsofboston
09/25/2019, 3:18 PMval clicks : Flow<Click> = ...
val operation: Flow<OperationResult> = ...
val clickAndThenOperation = clicks
.flatMapMerge {
operation.retry { throwable ->
// handle throwable
true
}
}
clickAndThenOperation.collect {
...
}
dave08
09/25/2019, 3:20 PMstreetsofboston
09/25/2019, 3:21 PMdave08
09/25/2019, 3:23 PMstreetsofboston
09/25/2019, 3:25 PMsuspend fun operation(): SomeResult
, you can do ::operation.asFlow()
dave08
09/25/2019, 3:26 PMstreetsofboston
09/25/2019, 3:27 PMval operationAsFlow = flow<SomeResult> { emit(operation(param1, param2)) }
dave08
09/25/2019, 3:29 PMDominaezzz
09/25/2019, 3:29 PM