Skip to content

Commit b868b24

Browse files
committed
Fixed sleeping action
1 parent 04068c1 commit b868b24

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

rxjava-core/src/main/java/rx/concurrency/SleepingAction.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@
2929
public SleepingAction(Func0<Subscription> underlying, Scheduler scheduler, long timespan, TimeUnit timeUnit) {
3030
this.underlying = underlying;
3131
this.scheduler = scheduler;
32-
this.execTime = scheduler.now() + timeUnit.toMillis(timespan);
32+
this.execTime = scheduler.now() + timeUnit.toNanos(timespan);
3333
}
3434

3535
@Override
3636
public Subscription call() {
37-
if (execTime < scheduler.now()) {
37+
if (execTime > scheduler.now()) {
3838
try {
39-
Thread.sleep(scheduler.now() - execTime);
39+
long nanos = execTime - scheduler.now();
40+
long milis = nanos / 1000000;
41+
if (milis > 0) {
42+
Thread.sleep(milis);
43+
}
4044
} catch (InterruptedException e) {
4145
Thread.currentThread().interrupt();
4246
throw new RuntimeException(e);

0 commit comments

Comments
 (0)