Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Dorus
    @Dorus

    here's an example of how you can make an IO reader:

    https://github.com/LeeCampbell/RxCookbook/tree/master/IO/Disk

    C# but it explains the concepts pretty nice.

    Derek Perez
    @perezd
    This one is a little weird mainly because I'm adapting some really incompatible concepts
    bzip -> csv
    bzip I can't do iteratively
    it has to be fully decompressed
    and then I can stream it
    so thats why its a little clunky
    purna455
    @purna455
    hi
    im looking for kafka-rx consumer sample in Java
    David Stemmer
    @weefbellington
    here is an rxjava pattern that I'm not familiar with -- inside an Observable.OnSubscribe implementation, I see a block like this:
    public void call(final Subscriber subscriber) {
        // some code here...
        subscriber.add(Subscriptions.create(new Action0() {
            someService.removeListener(listener);
        });
        someService.addListener(listener);
    }
    is this an accepted/common pattern for removing a listener when an observable is unsubscribed
    Dorus
    @Dorus
    subscriber.add acts like a compositeSubscription.
    Looks correct at first sight.
    I do wonder what the goal of that code it, all it does is binding the lifetime of the listener to the lifetime of the observable.
    David Stemmer
    @weefbellington
    there is more to it, it calls an external payment service and sets up a listener object to listen for a result. The listener object pushes the result to onNext. I suppose that this is supposed to unsubscribe the internal listener if the Observable is unsubscribed from
    Dorus
    @Dorus
    ah right, missed the // some code here....
    o
    David Stemmer
    @weefbellington
    the pattern is pretty interesting though...I see that Scheduler.Worker implements Subscription so you could do some work on a thread or an event loop and bail when unsubscribe is called
    maybe that's obvious but it wasn't to me ¯_(ツ)_/¯
    Dorus
    @Dorus
    I've seen the pattern before so i was familiar with it, but the first time i strumbled on it, it was pretty confusing also.
    And that was in C#, the scheduler.Schedule() they have is slightly more complicated, with recursive scheduling and more fun stuff.
    Artem Zinnatullin :slowpoke:
    @artem-zinnatullin
    @weefbellington subscriber implements Subscription and unfortunately add() is non-obviously named method to release resources when Subscription will be unsubscribed
    Dorus
    @Dorus
    The weird part is that the RxJS people decided to ditch CompositeDisposable in favor of subscriber.add in the next major update.
    David Stemmer
    @weefbellington
    @artem-zinnatullin I had forgotten that Subscriber implements Subscription. Is there a use case for doing subscriber.add(secondarySubscriber)in Observable.OnSubscribe#call(subscriber)? Would all onNext, onError, onCompleted etc. calls that pass through the original subscriber be forwarded to the secondary subscriber?
    Dorus
    @Dorus
    @weefbellington no. The signature is add(Subscription s) and Subscription is an interface with only isUnsubscribed() and unsubscribe(), so it can't even forwards events.
    Artem Zinnatullin :slowpoke:
    @artem-zinnatullin
    @weefbellington nope, Subscription.add() is as I said just for triggering some code when origin subscription gets unsubscribed, usually it's a good place to remove listeners/etc and anything that may create memory leaks
    thought it's not needed for most RxJava use cases
    David Stemmer
    @weefbellington
    ah. I should have looked more closely at the Subscription interface. OK, makes sense, even if it's a little unintuitive
    Dorus
    @Dorus
    Totally unintuitive yes.
    Derek Perez
    @perezd
    Is there a way to use lambdas with subscribe but retain the expected argument type?
    I keep getting handed Object and have to cast
    Derek Perez
    @perezd
    I think the problem is that JDK8 cannot figure out what the functional interface is.
    Dorus
    @Dorus
    Like (String str) -> println(str)?
    You might also have lost the type in a previous operator, might need to hint the compiler there.
    Typing can be hard in Java, it's rather limited sometimes.
    David Stemmer
    @weefbellington
    is there a version of merge that outputs an Observable that completes if any of the source observables complete? It looks like merge will only complete if all of the source observables complete
    Bob van der Linden
    @bobvanderlinden
    Is there a way to easily convert an Observable to a BehaviorSubject?
    Dorus
    @Dorus
    .replay(1)?
    Bob van der Linden
    @bobvanderlinden
    hmm, let me look into that
    @Dorus That does indeed sounds like what I'm looking for. Thanks!
    Dorus
    @Dorus
    ^_^
    Bob van der Linden
    @bobvanderlinden
    do you think it would be helpful to have a shorthand for replay(1).refCount(), just like share() is for .publish().refCount(), or would that clutter the API too much?
    Dorus
    @Dorus
    replay(1).refCount() sounds totally useless. What's your usecase?
    Bob van der Linden
    @bobvanderlinden
    i have an observable that represents the state of my view. it needs to be able to refresh and there are multiple views that are watching that observable. so if the state changes, the views need to be updated
    so, that's why I was thinking of something like BehaviorSubject
    Dorus
    @Dorus
    ah ic, makes sense then
    So the first subscription activates the view and the rest listens in
    Bob van der Linden
    @bobvanderlinden
    but a separate BehaviorSubject is too much of an hassle when you have a Observable already
    multiple views subscribe to the 'state'. When the first subscription is made, a state-retrieval-process starts running. I don't want multiple subscriptions to trigger multiple state-retrieval-processes, i just want one to run when multiple views are interested in the same state.
    to be less abstract: it's about the USB state of Android