Reputation: 3192
In my Android application I show list of user's photos. Photos are kept on server, and amount of photos may be very large. When user asks to show him photos, application gets from server first, say, 10 photos. Then user asks to show next 10, application loads 10 more, and so on. I use rx.Observable to load photos and show each of ones in subscriber's onNext(). But how could I tell Observable, when and how many photos to pull from server?
Have found a solution - use Producer. Here is a good article about producers.
Upvotes: 2
Views: 347
Reputation: 117174
My apologies for this being in C# (hopefully someone can translate for me).
You could try this:
var subject = new Subject<int>();
var query =
from count in subject
from image in GetImages(count)
select image;
query
.Subscribe(image =>
{
/* do something with each image */
});
You would just need to define your GetImages
method.
Now, when you want to call this code just do subject.OnNext(10)
when you want to get 10 images.
Upvotes: 1