These are chat archives for ReactiveX/RxJava

17th
Feb 2016
Josh Durbin
@joshdurbin
Feb 17 2016 01:28
Hey Everyone — I have a very, very specific question.
I’m using an implementation of a library, david moten’s tree - https://github.com/davidmoten/rtree - in which the tree itself is immutable, thus operations to mutate the tree result in a “view” of that object with the supplied operation result
I’ve got a basic API that allows insertion and query of the rtree, which supports rx query operations OOTB
I’ve wrapped the insert commands in a write lock, but i’m at a loss, if you will, how that impacts the read operations (as you’d typically also wrap your ‘read’ logic in read locks)
Mainly the insertPlace and getPlaces methods.
Dorus
@Dorus
Feb 17 2016 10:12

@joshdurbin
I didn't look at any of that, but i can give you the theory :)

If the tree is immutable, you do not need locks. Instead, any insert will traverse the tree, and create a new tree. Usually kept efficient by reusing unmodified parts of the old tree. That way, when you modify the tree, you receive a new tree that you then need to communicate to any reader that's consuming the tree. Only once you've communicated the new tree root, they will be able to read your modifications.

Boy Wang
@boyw165
Feb 17 2016 16:00
For a most basic observable, there's only one subscriber can subscribe to it at the same time, right?
Dorus
@Dorus
Feb 17 2016 16:01
no
Boy Wang
@boyw165
Feb 17 2016 16:02
Except PublishSubject, still no?
Dorus
@Dorus
Feb 17 2016 16:02
Observables are like function calls, you can call them multiple times but different calls wont affect each other.
At least for Cold observables
Hot observables do affect eachother, they share side effects.
PublishSubject is used to convert a cold observable into a hot one.
Boy Wang
@boyw165
Feb 17 2016 16:03
Oh I got it. So how do I build a pub-sub pattern by using observable? I want the observable can do some heavy image process when demand, and emit the result to all subscribers when done.
Dorus
@Dorus
Feb 17 2016 16:04
It pretty much already is.
Mostly you need to make your source hot.
Boy Wang
@boyw165
Feb 17 2016 16:05
Cool, HOT is the key. :D
Dorus
@Dorus
Feb 17 2016 16:05
Depending on the source, some sources are hot by default (fromEventPattern), others can be made hot with Publish.
In your case i assume you have something that makes requests to start the image processing, that's your source. And then you have a number of subscribers that want to receive updates.
Sounds like your source is already hot.
If your image processing happens inside the observable stream, you need to publish it also.
Boy Wang
@boyw165
Feb 17 2016 16:08
I see. So I have to figure out HOT observables.
Dorus
@Dorus
Feb 17 2016 16:08
if you push processed images directly into the stream, you don't need that.
Boy Wang
@boyw165
Feb 17 2016 16:11
Thanks. I checked out the session of "HOT" and "COLD" observables lately and was confused. Now I know which cases are they for from your kindly answer. :D
Dorus
@Dorus
Feb 17 2016 16:16
Oh btw, the easiest way to publish your source would be refCount/share.
Boy Wang
@boyw165
Feb 17 2016 16:17
Checking this out. :+1: