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

SwingScheduler: allow negative schedule #1195

Merged
merged 2 commits into from
May 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public boolean isUnsubscribed() {

@Override
public Subscription schedule(final Action0 action, long delayTime, TimeUnit unit) {
long delay = unit.toMillis(delayTime);
long delay = Math.max(0, unit.toMillis(delayTime));
assertThatTheDelayIsValidForTheSwingTimer(delay);
final BooleanSubscription s = BooleanSubscription.create();
class ExecuteOnceAction implements ActionListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ public void testInvalidDelayValues() {
final Worker inner = scheduler.createWorker();
final Action0 action = mock(Action0.class);

exception.expect(IllegalArgumentException.class);
inner.schedulePeriodically(action, -1L, 100L, TimeUnit.SECONDS);

exception.expect(IllegalArgumentException.class);
inner.schedulePeriodically(action, 100L, -1L, TimeUnit.SECONDS);

exception.expect(IllegalArgumentException.class);
Expand Down
13 changes: 9 additions & 4 deletions rxjava-core/src/main/java/rx/Scheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ public abstract static class Worker implements Subscription {

/**
* Schedules an Action for execution at some point in the future.
*
* <p>Note to implementors: non-positive {@code delayTime} should be regarded as
* undelayed schedule, i.e., as if the {@link #schedule(rx.functions.Action0)} was called.
* @param action
* the Action to schedule
* @param delayTime
* time to wait before executing the action
* time to wait before executing the action, non-positive values indicate an undelayed schedule
* @param unit
* the time unit the delay time is given in
* @return a subscription to be able to unsubscribe the action (unschedule it if not executed)
Expand All @@ -86,13 +87,17 @@ public abstract static class Worker implements Subscription {
* Schedules a cancelable action to be executed periodically. This default implementation schedules
* recursively and waits for actions to complete (instead of potentially executing long-running actions
* concurrently). Each scheduler that can do periodic scheduling in a better way should override this.
* <p>Note to implementors: non-positive {@code initialTime} and {@code period} should be regarded as
* undelayed scheduling of the first and any subsequent executions.
*
* @param action
* the Action to execute periodically
* @param initialDelay
* time to wait before executing the action for the first time
* time to wait before executing the action for the first time,
* non-positive values indicate an undelayed schedule
* @param period
* the time interval to wait each time in between executing the action
* the time interval to wait each time in between executing the action,
* non-positive values indicate no delay between repeated schedules
* @param unit
* the time unit the interval above is given in
* @return a subscription to be able to unsubscribe the action (unschedule it if not executed)
Expand Down