-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Scheduler with Recurse/Inner #1014
Conversation
API changes as per ReactiveX#997
RxJava-pull-requests #941 ABORTED |
I would go for a combined |
The problem I've had with combining them is that when first creating an The reason for this scenario is that retrieving an protected void schedule() {
if (counter.getAndIncrement() == 0) {
if (recursiveScheduler == null) {
recursiveScheduler = scheduler.createInner();
add(recursiveScheduler);
}
recursiveScheduler.schedule(new Action1<Recurse>() {
@Override
public void call(Recurse inner) {
pollQueue();
}
});
}
} The reason is that the recursion happens externally (the operator is doing it) rather than internally (inside the Therefore, we have use cases where |
Now the solution is passing a scheduler to the user. I just got an opposite idea. Can we let the user tell us how to schedule. For example, public class Scheduler {
public final Subscription schedule(Func1<ScheduleAction, ScheduleAction> action);
public final Subscription schedule(Func1<ScheduleAction, ScheduleAction> action, final long delayTime, final TimeUnit unit);
public final Subscription schedulePeriodically(Func1<ScheduleAction, ScheduleAction> action, long initialDelay, long period, TimeUnit unit);
public abstract Inner createInner(); // for advanced use cases like `observeOn`
public int degreeOfParallelism();
public long now();
public static final class ScheduleAction {
private static final none = new ScheduleAction();
public static final ScheduleAction none() {
return none;
}
public ScheduleAction(Action1<Recurse> action, long initialDelay, long period, TimeUnit unit) {
...
}
...
}
// now mostly an implementation detail except for advanced use cases
public abstract static class Inner implements Subscription {
public abstract void schedule(ScheduleAction);
public long now();
}
public static void main(String[] args) {
Scheduler scheduler = ...;
// recursively schedule the current action
scheduler.schedule(new Func1<ScheduleAction, ScheduleAction>() {
public ScheduleAction call(ScheduleAction action) {
...
return action;
}
});
// create a new ScheduleAction
scheduler.schedule(new Func1<ScheduleAction, ScheduleAction>() {
public ScheduleAction call(ScheduleAction action) {
...
return new ScheduleAction(...);
}
});
// quit the recursive schedule process
scheduler.schedule(new Func1<ScheduleAction, ScheduleAction>() {
public ScheduleAction call(ScheduleAction action) {
...
return ScheduleAction.none();
}
});
}
} We send the current |
What's more, if we change |
@zsxwing I don't understand what the |
Discussion of the signatures are continuing at #997 |
Agreed. I gave up the Func1 idea. |
API changes as per #997
Usage looks like this:
Code outline: