How to ignore error and continue infinite stream?

后端 未结 10 1757
执念已碎
执念已碎 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

    This answer might be a bit late, but if anyone stumbles upon this, instead of reinventing a wheel can use the ready to use Relay lib by Jacke Wharton

    https://github.com/JakeWharton/RxRelay

    there is good documentation but in essence, Relay is A Subject except without the ability to call onComplete or onError.

    and the options are:

    BehaviorRelay

    Relay that emits the most recent item it has observed and all subsequent observed items to each subscribed Observer.
    
        // observer will receive all events.
        BehaviorRelay relay = BehaviorRelay.createDefault("default");
        relay.subscribe(observer);
        relay.accept("one");
        relay.accept("two");
        relay.accept("three");
    
        // observer will receive the "one", "two" and "three" events, but not "zero"
        BehaviorRelay relay = BehaviorRelay.createDefault("default");
        relay.accept("zero");
        relay.accept("one");
        relay.subscribe(observer);
        relay.accept("two");
        relay.accept("three");
    
    
    

    PublishRelay Relay that, once an Observer has subscribed, emits all subsequently observed items to the subscriber.

        PublishRelay relay = PublishRelay.create();
        // observer1 will receive all events
        relay.subscribe(observer1);
        relay.accept("one");
        relay.accept("two");
        // observer2 will only receive "three"
        relay.subscribe(observer2);
        relay.accept("three");
    
    

    ReplayRelay Relay that buffers all items it observes and replays them to any Observer that subscribes.

        ReplayRelay relay = ReplayRelay.create();
        relay.accept("one");
        relay.accept("two");
        relay.accept("three");
        // both of the following will get the events from above
        relay.subscribe(observer1);
        relay.subscribe(observer2);
    
        

    提交回复
    热议问题