I am using the Android ReactiveLocation library to receive regular location updates. I want to keep receiving location updates even if nothing in my app is using them, so that I always have an up-to-date location I can use immediately if I need to.
This is how I start getting location updates in a core component of my app. I want to republish the latest value, and any new detected locations, to any subscriber further down the chain in my app, and this is what the replay(1)
is for.
locationProvider = new ReactiveLocationProvider(context);
locationObservable = locationProvider.getUpdatedLocation(locationRequest)
.replay(1);
Elsewhere in the app, I subscribe to this republished obervable:
locationSubscription = locationObservable
.filter(new Func1<Location, Boolean>() {
@Override
public Boolean call(Location location) {
return location.getAccuracy() < LOCATION_ACCURACY_THRESHOLD;
}
})
.subscribe(new Action1<Location>() {
@Override
public void call(Location location) {
}
});
This appears to do the job: my eventual subscriber gets the latest location returned immediately, and continues to receive new updates, but I want to make sure I'm not building up a huge buffer of unused locations somewhere in the chain when the final subscriber is not subscribed. I'm an Rx noob. How does backpressure apply to this situation? Is replay(1)
doing what I expect, and discarding all unwanted locations apart from the latest one?