-
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
recursive scheduling in RxScala #1537
Conversation
RxJava-pull-requests #1462 FAILURE |
Not sure why the cloudbees build fails. The assertion error in |
* @param action the Action to schedule recursively | ||
* @return a subscription to be able to unsubscribe the action | ||
*/ | ||
def scheduleRec(action: => Unit): Subscription = { |
There was a problem hiding this comment.
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)
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Reviewed with @headinthebox |
recursive scheduling in RxScala
This PR adds a
scheduleRec
method to theScheduler.Worker
trait to make recursive scheduling more convenient in Scala. This issue is raised in #1348.