-
Notifications
You must be signed in to change notification settings - Fork 7.6k
"Gate" operator #4210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Looks interesting, here are my thoughts:
Actually, it's a nice job for a first-time writer.
We don't have any operators that let you do this in-sequence request manipulation. |
I've been interested in high level operators that allow the use of Observable APIs to enable manipulation of behavior rather then data of other Observables. For example the here are a few of the things that I've been trying to work on:
This seem interesting but I'm wondering if the API could be implemented as an Observable chain to allow others to come up with their own behaviors by composing standard operators. |
@akarnokd I've updated the gist with your suggestions.
Done.
I've wrapped the child with SerializedSubscriber, but I'm not sure what you mean about not needing to CAS. Do you mean I no longer need to use an AtomicBoolean? Or do you mean I could do public void onCompleted() {
if (!completed.get()) {
completed.set(false);
child.onCompleted();
}
} in which case
AtomicLong doesn't have just an add method, addAndGet is the best alternative
Done.
Do you want more explanation on what's going on? Basically the
Nice tip, thanks! |
public void onCompleted() {
child.onCompleted();
}
No I get it. |
I don't think that would work in my case since I'm not resubscribing to Observables. I probably could adapt an Observable to work like that, but it wouldn't be as clear.
That could work, something like readFromDatabase()
.observeOn(Schedulers.io().when(runTasksBasedOnRecyclerView()))
...
That does look similar. Something like this: PublishRelay<Boolean> relay = PublishRelay.create();
readFromDatabase()
.pressureValve(relay, 1)
.doOnNext(x -> relay.call(false))
...
void loadMore() {
relay.call(true);
} I haven't tested either of these methods yet, it seems
I did actually have a version using |
Closing since I'm happy with the implementation, thanks for all the help. |
I've also found |
Sorry @GrahamRogers, I wasn't trying to suggest that you use retryWhen or Scheduler.when. I was trying to express a theme that I've been following of operators that use observables for the composition behavior and not for the processing data. I was wondering if gate could follow that theme? @davidmoten That was one of the steps along the way to the development of "getting a more ways to configure retrying":
That is how OnSubscribeRedo came to be the mother of all subscription mangling. I've been thinking that that now that we have Single and Completable it might be easier to constrain what is expected of the function. |
I've written a custom RxJava operator and wanted to check whether this was the best way to do what I want and also to make sure it is implemented correctly. Code is here.
My use case for this operator is an Android
RecyclerView
backed by anObservable
, in my case theObservable
reads from the local database and might do some network calls. The issue is a user could have hundreds of items produced by thisObservable
, and each one might require its own network call. Since I don't want to make hundreds of network calls at once, I want theRecyclerView
to lazily load the values. Think an inifinitely-scrollingRecyclerView
.What this operator does is it takes an
Observable<Long>
and whenever that produces a value it will request that many values from theProducer
for the actualObservable
. For example:My implementation seems to work, but I would like an RxJava expert's opinion on whether it's correct (or even if it's a sensible approach) since I've never written an operator before.
The text was updated successfully, but these errors were encountered: