Skip to content

Commit

Permalink
[Streaming][Minor]Replace some 'if-else' in Clock
Browse files Browse the repository at this point in the history
Replace some 'if-else' statement by math.min and math.max in Clock.scala

Author: huangzhaowei <carlmartinmax@gmail.com>

Closes apache#3088 from SaintBacchus/StreamingClock and squashes the following commits:

7b7f8e7 [huangzhaowei] [Streaming][Minor]Replace some 'if-else' in Clock
  • Loading branch information
SaintBacchus authored and tdas committed Nov 11, 2014
1 parent c8850a3 commit 6e03de3
Showing 1 changed file with 2 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,15 @@ class SystemClock() extends Clock {
return currentTime
}

val pollTime = {
if (waitTime / 10.0 > minPollTime) {
(waitTime / 10.0).toLong
} else {
minPollTime
}
}
val pollTime = math.max(waitTime / 10.0, minPollTime).toLong

while (true) {
currentTime = System.currentTimeMillis()
waitTime = targetTime - currentTime
if (waitTime <= 0) {
return currentTime
}
val sleepTime =
if (waitTime < pollTime) {
waitTime
} else {
pollTime
}
val sleepTime = math.min(waitTime, pollTime)
Thread.sleep(sleepTime)
}
-1
Expand Down

0 comments on commit 6e03de3

Please sign in to comment.