Skip to content

Commit 92e8803

Browse files
Merge pull request #5 from cbeams/handle-negative-delays
Handle negative delay times
2 parents c9c5574 + 16155fb commit 92e8803

File tree

3 files changed

+8
-28
lines changed

3 files changed

+8
-28
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ language: java
22

33
jdk:
44
- oraclejdk8
5+
6+
before_install:
7+
- export DISPLAY=:99.0
8+
- sh -e /etc/init.d/xvfb start

src/main/java/rx/schedulers/JavaFxScheduler.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
import java.util.concurrent.TimeUnit;
3232

33+
import static java.lang.Math.max;
34+
3335
/**
3436
* Executes work on the JavaFx UI thread.
3537
* This scheduler should only be used with actions that execute quickly.
@@ -44,12 +46,6 @@ public static JavaFxScheduler getInstance() {
4446
return INSTANCE;
4547
}
4648

47-
private static void assertThatTheDelayIsValidForTheJavaFxTimer(long delay) {
48-
if (delay < 0 || delay > Integer.MAX_VALUE) {
49-
throw new IllegalArgumentException(String.format("The JavaFx timer only accepts non-negative delays up to %d milliseconds.", Integer.MAX_VALUE));
50-
}
51-
}
52-
5349
@Override
5450
public Worker createWorker() {
5551
return new InnerJavaFxScheduler();
@@ -71,10 +67,9 @@ public boolean isUnsubscribed() {
7167

7268
@Override
7369
public Subscription schedule(final Action0 action, long delayTime, TimeUnit unit) {
74-
long delay = unit.toMillis(delayTime);
75-
assertThatTheDelayIsValidForTheJavaFxTimer(delay);
7670
final BooleanSubscription s = BooleanSubscription.create();
7771

72+
final long delay = unit.toMillis(max(delayTime, 0));
7873
final Timeline timeline = new Timeline(new KeyFrame(Duration.millis(delay), new EventHandler<ActionEvent>() {
7974

8075
@Override

src/test/java/rx/schedulers/JavaFxSchedulerTest.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,6 @@ public void run() {
7373
t.start();
7474
}
7575

76-
@Test
77-
public void testInvalidDelayValues() {
78-
final JavaFxScheduler scheduler = new JavaFxScheduler();
79-
final Worker inner = scheduler.createWorker();
80-
final Action0 action = mock(Action0.class);
81-
82-
exception.expect(IllegalArgumentException.class);
83-
inner.schedulePeriodically(action, -1L, 100L, TimeUnit.SECONDS);
84-
85-
exception.expect(IllegalArgumentException.class);
86-
inner.schedulePeriodically(action, 100L, -1L, TimeUnit.SECONDS);
87-
88-
exception.expect(IllegalArgumentException.class);
89-
inner.schedulePeriodically(action, 1L + Integer.MAX_VALUE, 100L, TimeUnit.MILLISECONDS);
90-
91-
exception.expect(IllegalArgumentException.class);
92-
inner.schedulePeriodically(action, 100L, 1L + Integer.MAX_VALUE / 1000, TimeUnit.SECONDS);
93-
}
94-
9576
@Test
9677
public void testPeriodicScheduling() throws Exception {
9778
final JavaFxScheduler scheduler = new JavaFxScheduler();
@@ -114,7 +95,7 @@ public void call() {
11495

11596
inner.schedulePeriodically(action, 50, 200, TimeUnit.MILLISECONDS);
11697

117-
if (!latch.await(5000, TimeUnit.MILLISECONDS)) {
98+
if (!latch.await(1, TimeUnit.SECONDS)) {
11899
fail("timed out waiting for tasks to execute");
119100
}
120101

0 commit comments

Comments
 (0)