From b868b24c3b1e981e52ae8bc82c50a94f615812cd Mon Sep 17 00:00:00 2001 From: Mairbek Khadikov Date: Wed, 17 Apr 2013 13:28:42 +0300 Subject: [PATCH] Fixed sleeping action --- .../src/main/java/rx/concurrency/SleepingAction.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rxjava-core/src/main/java/rx/concurrency/SleepingAction.java b/rxjava-core/src/main/java/rx/concurrency/SleepingAction.java index a57fd9046d..afc3054202 100644 --- a/rxjava-core/src/main/java/rx/concurrency/SleepingAction.java +++ b/rxjava-core/src/main/java/rx/concurrency/SleepingAction.java @@ -29,14 +29,18 @@ public SleepingAction(Func0 underlying, Scheduler scheduler, long timespan, TimeUnit timeUnit) { this.underlying = underlying; this.scheduler = scheduler; - this.execTime = scheduler.now() + timeUnit.toMillis(timespan); + this.execTime = scheduler.now() + timeUnit.toNanos(timespan); } @Override public Subscription call() { - if (execTime < scheduler.now()) { + if (execTime > scheduler.now()) { try { - Thread.sleep(scheduler.now() - execTime); + long nanos = execTime - scheduler.now(); + long milis = nanos / 1000000; + if (milis > 0) { + Thread.sleep(milis); + } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e);