hey guys, I’d like some help figuring out how to b...
# rx
r
hey guys, I’d like some help figuring out how to better handle errors emitted from this observable. I want to parse multiple files eagerly, then wait for all of them to complete, and know which files failed. Is this possible? This is what I have so far:
Copy code
fun parseObservable(f: File): Observable<Item> { ... }

Observable.fromIterable(List<File>)
                .concatMapEagerDelayError({ parseObservable(it) }, true)
                .toList()
                .subscribeOn(<http://Schedulers.io|Schedulers.io>())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe { items -> ... }
r
You could catch the failure and wrap it. e.g.
Copy code
sealed class Result(){
  class Content(val content: Type) : Result
  class Error(val error: Throwable): Result
}
Then you have a list of
Result
and you can decide what to do based on the type of
Result
it is
👍 1
u
If you want to wait for all to complete/error, not the first one, then you dont want rx error at all, since that is like a exception, it exits your normal flow. So, yes what above is said, map it into some error constant / wrap into Result type. Then use Single.zip for example
r
Thanks again guys! Here’s what I ended up with:
Copy code
fun parseObservable(f: File): Observable<Result> {
    ...
    .map { Success(f, it) }
    .onErrorResumeNext { Single.just(Failure(f, it)) }
    .toObservable()
}

Observable.fromIterable(List<File>)
                .concatMapEager { parseObservable(it) }
                .toList()
                .subscribe { results -> ... }
👍 1
u
@reline onErrorReturn { t -> Failure(...) }
🙏 1