Skip to content
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

recursive scheduling in RxScala #1537

Merged
merged 1 commit into from
Aug 8, 2014
Merged

recursive scheduling in RxScala #1537

merged 1 commit into from
Aug 8, 2014

Conversation

flatmap13
Copy link
Contributor

This PR adds a scheduleRec method to the Scheduler.Worker trait to make recursive scheduling more convenient in Scala. This issue is raised in #1348.

@cloudbees-pull-request-builder

RxJava-pull-requests #1462 FAILURE
Looks like there's a problem with this pull request

@flatmap13
Copy link
Contributor Author

Not sure why the cloudbees build fails. The assertion error in rx.BackpressureTests.testMergeAsyncThenObserveOn has nothing to do with these changes. Also, the build succeeds locally with the changes merged into the latest master.

* @param action the Action to schedule recursively
* @return a subscription to be able to unsubscribe the action
*/
def scheduleRec(action: => Unit): Subscription = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

action: => Unit cannot support something like "repeat an action 10 times". Because worker.unsubscribe() will cancel all scheduled work, we cannot use it to abort the recursive schedule but let the running actions finish their work.
I prefer def scheduleRec(f: => Boolean): Subscription. Here the value of f means if we want to continue the recursive schedule:

  def scheduleRec(f: => Boolean): Subscription = {
    def work: Unit = {
      if (f && !this.isUnsubscribed) {
        this.schedule(work)
      }
    }
    this.schedule(work)
  }

/cc @headinthebox @samuelgruetter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that I like => Boolean, I'd rather encode the boolean myself and don't call schedule when it is true, a signature => Boolean is a bit too overly stateful for my tast.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather encode the boolean myself

That's fine. Then I'm OK with action: => Unit now.

@benjchristensen
Copy link
Member

Reviewed with @headinthebox

benjchristensen added a commit that referenced this pull request Aug 8, 2014
recursive scheduling in RxScala
@benjchristensen benjchristensen merged commit b34bc69 into ReactiveX:master Aug 8, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants