How to ignore error and continue infinite stream?

后端 未结 10 1754
执念已碎
执念已碎 2020-12-05 06:18

I would like to know how to ignore exceptions and continue infinite stream (in my case stream of locations)?

I\'m fetching current user position (using Android-React

10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 07:04

    Here is my kotlin extension function for ignoring errors

    fun  Observable.ignoreErrors(errorHandler: (Throwable) -> Unit) =
        retryWhen { errors ->
            errors
                .doOnNext { errorHandler(it) }
                .map { 0 }
        }
    

    This utilizes retryWhen to indefinately re-subscribe to the upstream while still allowing you a method of handling the error in a non terminal way.

    This feels dangerous

提交回复
热议问题