Skip to content

Commit d64b3a1

Browse files
Merge pull request #1195 from akarnokd/SwingSchedulerNegativeFix
SwingScheduler: allow negative schedule
2 parents e5b75eb + 8dad2ec commit d64b3a1

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

rxjava-contrib/rxjava-swing/src/main/java/rx/schedulers/SwingScheduler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public boolean isUnsubscribed() {
6464

6565
@Override
6666
public Subscription schedule(final Action0 action, long delayTime, TimeUnit unit) {
67-
long delay = unit.toMillis(delayTime);
67+
long delay = Math.max(0, unit.toMillis(delayTime));
6868
assertThatTheDelayIsValidForTheSwingTimer(delay);
6969
final BooleanSubscription s = BooleanSubscription.create();
7070
class ExecuteOnceAction implements ActionListener {

rxjava-contrib/rxjava-swing/src/test/java/rx/schedulers/SwingSchedulerTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ public void testInvalidDelayValues() {
5151
final Worker inner = scheduler.createWorker();
5252
final Action0 action = mock(Action0.class);
5353

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

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

6058
exception.expect(IllegalArgumentException.class);

rxjava-core/src/main/java/rx/Scheduler.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ public abstract static class Worker implements Subscription {
7171

7272
/**
7373
* Schedules an Action for execution at some point in the future.
74-
*
74+
* <p>Note to implementors: non-positive {@code delayTime} should be regarded as
75+
* undelayed schedule, i.e., as if the {@link #schedule(rx.functions.Action0)} was called.
7576
* @param action
7677
* the Action to schedule
7778
* @param delayTime
78-
* time to wait before executing the action
79+
* time to wait before executing the action, non-positive values indicate an undelayed schedule
7980
* @param unit
8081
* the time unit the delay time is given in
8182
* @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 {
8687
* Schedules a cancelable action to be executed periodically. This default implementation schedules
8788
* recursively and waits for actions to complete (instead of potentially executing long-running actions
8889
* concurrently). Each scheduler that can do periodic scheduling in a better way should override this.
90+
* <p>Note to implementors: non-positive {@code initialTime} and {@code period} should be regarded as
91+
* undelayed scheduling of the first and any subsequent executions.
8992
*
9093
* @param action
9194
* the Action to execute periodically
9295
* @param initialDelay
93-
* time to wait before executing the action for the first time
96+
* time to wait before executing the action for the first time,
97+
* non-positive values indicate an undelayed schedule
9498
* @param period
95-
* the time interval to wait each time in between executing the action
99+
* the time interval to wait each time in between executing the action,
100+
* non-positive values indicate no delay between repeated schedules
96101
* @param unit
97102
* the time unit the interval above is given in
98103
* @return a subscription to be able to unsubscribe the action (unschedule it if not executed)

0 commit comments

Comments
 (0)