diff --git a/rxjava-core/src/main/java/rx/Scheduler.java b/rxjava-core/src/main/java/rx/Scheduler.java index fd93a92972..29d5e70f99 100644 --- a/rxjava-core/src/main/java/rx/Scheduler.java +++ b/rxjava-core/src/main/java/rx/Scheduler.java @@ -94,6 +94,57 @@ public void call(Inner inner) { return schedule(recursiveAction, initialDelay, unit); } + public final Subscription scheduleRecursive(final Action1 action) { + return schedule(new Action1() { + + @Override + public void call(Inner inner) { + action.call(new Recurse(inner, action)); + } + + }); + } + + public static final class Recurse { + final Action1 action; + final Inner inner; + + private Recurse(Inner inner, Action1 action) { + this.inner = inner; + this.action = action; + } + + /** + * Schedule the current function for execution immediately. + */ + public final void schedule() { + final Recurse self = this; + inner.schedule(new Action1() { + + @Override + public void call(Inner _inner) { + action.call(self); + } + + }); + } + + /** + * Schedule the current function for execution in the future. + */ + public final void schedule(long delay, TimeUnit unit) { + final Recurse self = this; + inner.schedule(new Action1() { + + @Override + public void call(Inner _inner) { + action.call(self); + } + + }, delay, unit); + } + } + public abstract static class Inner implements Subscription { /**