diff --git a/rxjava-contrib/rxjava-swing/src/main/java/rx/schedulers/SwingScheduler.java b/rxjava-contrib/rxjava-swing/src/main/java/rx/schedulers/SwingScheduler.java index c63655a3a4..5786425cf3 100644 --- a/rxjava-contrib/rxjava-swing/src/main/java/rx/schedulers/SwingScheduler.java +++ b/rxjava-contrib/rxjava-swing/src/main/java/rx/schedulers/SwingScheduler.java @@ -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 { diff --git a/rxjava-contrib/rxjava-swing/src/test/java/rx/schedulers/SwingSchedulerTest.java b/rxjava-contrib/rxjava-swing/src/test/java/rx/schedulers/SwingSchedulerTest.java index 40b6a475d3..5938c336b9 100644 --- a/rxjava-contrib/rxjava-swing/src/test/java/rx/schedulers/SwingSchedulerTest.java +++ b/rxjava-contrib/rxjava-swing/src/test/java/rx/schedulers/SwingSchedulerTest.java @@ -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); diff --git a/rxjava-core/src/main/java/rx/Scheduler.java b/rxjava-core/src/main/java/rx/Scheduler.java index e8352672ce..95fd31d85e 100644 --- a/rxjava-core/src/main/java/rx/Scheduler.java +++ b/rxjava-core/src/main/java/rx/Scheduler.java @@ -71,11 +71,12 @@ public abstract static class Worker implements Subscription { /** * Schedules an Action for execution at some point in the future. - * + *
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) @@ -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. + *
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)